将RethinkDB文档推送到RQ队列时出现UnpickleError

时间:2014-09-08 19:10:53

标签: python datetime rethinkdb python-rq

我从RethinkDB数据库检索的文档中有一个时间戳(表示为Python datetime.datetime对象,其tzinfo类型的rethinkdb.ast.RqlTzinfo特殊值。

当将其推送到RQ任务队列时,当任务尝试取消时间戳的取消时,我在另一端收到UnpickleError。

feeds = r.table('feeds') \
    .filter(lambda feed: feed['last_fetched'] \
        < (r.now() - config.FEED_REFRESH_INTERVAL)) \
    .pluck('id', 'feed_url', 'last_fetched').run(db)

q = Queue('feed_fetcher', connection=Redis())

for feed in feeds:
    print(feed['last_fetched']) # 2014-09-08 18:35:22.735000+00:00
    result = q.enqueue(fetch_feed, feed)

RQ工作人员的输出:

18:48:34 *** Listening on feed_fetcher...
19:05:01 feed_fetcher: app.feedupdater.tasks.fetch_feed({u'last_fetched': datetime.datetime(2014, 9, 8, 18, 35, 22, 735000, tzinfo=<rethinkdb.ast.RqlTzinfo object at 0x7fdf508ed410>), u'id': u'ccd57063-a61a-4255-af67-94c244ff6bbb', u'feed_url': u'http://feeds.feedburner.com/hacker-news-feed-200?format=xml'}) (0002de8d-978c-4aeb-944e-2559458d114c)
Traceback (most recent call last):
  File "/usr/local/bin/rqworker", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/rq/scripts/rqworker.py", line 100, in main
    w.work(burst=args.burst)
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 358, in work
    self.execute_job(job)
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 422, in execute_job
    self.main_work_horse(job)
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 457, in main_work_horse
    success = self.perform_job(job)
  File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 473, in perform_job
    job.func_name,
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 225, in func_name
    self._unpickle_data()
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 193, in _unpickle_data
    self._func_name, self._instance, self._args, self._kwargs = unpickle(self.data)
  File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 50, in unpickle
    raise UnpickleError('Could not unpickle.', pickled_string, e)
rq.exceptions.UnpickleError: (u'Could not unpickle.', TypeError('__init__() takes exactly 2 arguments (1 given)', <class 'rethinkdb.ast.RqlTzinfo'>, ()))

我已经成功地解决了这个问题,在推入队列之前将时间戳替换为纪元时间,但它是一个止损解决方案并且让事情变得有点复杂,因为我在将纪元时间恢复到datetime对象之前,必须处理时区等,然后再将其填充回数据库。

问题出在哪里(是RethinkDB&#39;} RqlTzinfo对象还是RQ的破坏性实现)这是一个合法的错误还是仅仅是我的糟糕实现?

1 个答案:

答案 0 :(得分:0)

已提交修复程序,并在1.15.1版本中提供。这不再是一个问题。请参阅:https://github.com/rethinkdb/rethinkdb/issues/3024