本文整理汇总了Python中pyres.ResQ._current_time方法的典型用法代码示例。如果您正苦于以下问题:Python ResQ._current_time方法的具体用法?Python ResQ._current_time怎么用?Python ResQ._current_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyres.ResQ
的用法示例。
在下文中一共展示了ResQ._current_time方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: retry
# 需要导入模块: from pyres import ResQ [as 别名]
# 或者: from pyres.ResQ import _current_time [as 别名]
def retry(self, payload_class, args):
"""This method provides a way to retry a job after a failure.
If the jobclass defined by the payload containes a ``retry_every``
attribute then pyres will attempt to retry the job until successful
or until timeout defined by ``retry_timeout`` on the payload class.
:param payload_class: the :class:`Job`-like class that needs
to be retried
:type payload_class: :class:`Job`-like
:param args: The args to be passed to the `payload_class.perform`
method when it is retried.
:type args: list
"""
retry_every = getattr(payload_class, 'retry_every', None)
retry_timeout = getattr(payload_class, 'retry_timeout', 0)
if retry_every:
now = ResQ._current_time()
first_attempt = self._payload.get("first_attempt", now)
retry_until = first_attempt + timedelta(seconds=retry_timeout)
retry_at = now + timedelta(seconds=retry_every)
if retry_at < retry_until:
self.resq.enqueue_at(retry_at, payload_class, *args,
**{'first_attempt':first_attempt})
return True
return False
示例2: retry
# 需要导入模块: from pyres import ResQ [as 别名]
# 或者: from pyres.ResQ import _current_time [as 别名]
def retry(self, payload_class, args):
retry_every = getattr(payload_class, 'retry_every', None)
retry_timeout = getattr(payload_class, 'retry_timeout', 0)
if retry_every:
now = ResQ._current_time()
first_attempt = self._payload.get("first_attempt", now)
retry_until = first_attempt + timedelta(seconds=retry_timeout)
retry_at = now + timedelta(seconds=retry_every)
if retry_at < retry_until:
self.resq.enqueue_at(retry_at, payload_class, *args,
**{'first_attempt':first_attempt})
return True
return False
示例3: retry
# 需要导入模块: from pyres import ResQ [as 别名]
# 或者: from pyres.ResQ import _current_time [as 别名]
def retry(self, payload_class, args):
"""This method provides a way to retry a job after a failure.
If the jobclass defined by the payload containes a ``retry_every`` attribute then pyres
will attempt to retry the job until successful or until timeout defined by ``retry_timeout`` on the payload class.
"""
retry_every = getattr(payload_class, "retry_every", None)
retry_timeout = getattr(payload_class, "retry_timeout", 0)
if retry_every:
now = ResQ._current_time()
first_attempt = self._payload.get("first_attempt", now)
retry_until = first_attempt + timedelta(seconds=retry_timeout)
retry_at = now + timedelta(seconds=retry_every)
if retry_at < retry_until:
self.resq.enqueue_at(retry_at, payload_class, *args, **{"first_attempt": first_attempt})
return True
return False
示例4: perform
# 需要导入模块: from pyres import ResQ [as 别名]
# 或者: from pyres.ResQ import _current_time [as 别名]
def perform(fail_until):
if ResQ._current_time() < fail_until:
raise Exception("Don't blame me! I'm supposed to fail!")
else:
return True