所以我有一个django网站,它给了我这个AmbiguousTimeError。保存产品时,如果在更新搜索索引之前短暂超时,则会激活作业。看起来在夏令时时间内进行了更新,而pytz无法弄清楚如何处理它。
如何在DST下一次换班时防止这种情况发生?
[2012-11-06 14:22:52,115: ERROR/MainProcess] Unrecoverable error: AmbiguousTimeError(datetime.datetime(2012, 11, 4, 1, 11, 4, 335637),)
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/celery/worker/__init__.py", line 353, in start
component.start()
File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 369, in start
self.consume_messages()
File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 842, in consume_messages
self.connection.drain_events(timeout=10.0)
File "/usr/local/lib/python2.6/dist-packages/kombu/connection.py", line 191, in drain_events
return self.transport.drain_events(self.connection, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/kombu/transport/virtual/__init__.py", line 760, in drain_events
self._callbacks[queue](message)
File "/usr/local/lib/python2.6/dist-packages/kombu/transport/virtual/__init__.py", line 465, in _callback
return callback(message)
File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py", line 485, in _receive_callback
self.receive(decoded, message)
File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py", line 457, in receive
[callback(body, message) for callback in callbacks]
File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 560, in receive_message
self.strategies[name](message, body, message.ack_log_error)
File "/usr/local/lib/python2.6/dist-packages/celery/worker/strategy.py", line 25, in task_message_handler
delivery_info=message.delivery_info))
File "/usr/local/lib/python2.6/dist-packages/celery/worker/job.py", line 120, in __init__
self.eta = tz_to_local(maybe_iso8601(eta), self.tzlocal, tz)
File "/usr/local/lib/python2.6/dist-packages/celery/utils/timeutils.py", line 52, in to_local
dt = make_aware(dt, orig or self.utc)
File "/usr/local/lib/python2.6/dist-packages/celery/utils/timeutils.py", line 211, in make_aware
return localize(dt, is_dst=None)
File "/usr/local/lib/python2.6/dist-packages/pytz/tzinfo.py", line 349, in localize
raise AmbiguousTimeError(dt)
AmbiguousTimeError: 2012-11-04 01:11:04.335637
编辑:我在芹菜中使用此代码暂时修复了它:
芹菜/工人/ job.py @第120行
try:
self.eta = tz_to_local(maybe_iso8601(eta), self.tzlocal, tz)
except:
self.eta = None
我不想在pip安装的应用程序中进行更改,因此我需要修复我的代码中的内容:
当我保存我的应用程序时运行:
self.task_cls.apply_async(
args=[action, get_identifier(instance)],
countdown=15
)
我假设我需要以某种方式检测我是否处于模棱两可的时间并调整倒计时。
答案 0 :(得分:1)
我想我将不得不清除解决这个问题的任务,但是如何在DST下一小时转换时防止这种情况发生?
目前尚不清楚你在做什么(你没有显示任何代码),但基本上你需要考虑世界的运作方式。当时间倒退一小时时,您无法避免在从本地时间转换为UTC(或转换到不同区域的本地时间)时出现模糊不清的时间。
同样地,你应该意识到存在“差距”或“不可能”的时间,其中没有发生合理的当地时间。
我不知道Python为您提供了哪些选项,但理想情况下,API可以让您根据需要解决不明确的时间 - 无论是抛出错误,还是更早出现,后续发生或其他事情。
答案 1 :(得分:0)
显然,Celery解决了这个问题: