from redis import Redis
from rq import Queue, Retry
from somewhere import randomly_failing_task, dependent_task
job_queue = Queue(connection=Redis())
randomly_failing_job = job_queue.enqueue(randomly_failing_task, retry=Retry(max=3))
dependent_job = job_queue.enqueue(dependent_task, depends_on=randomly_failing_job)
以及示例任务:
from random import choice
def randomly_failing_task():
print('I am a task, I will fail 50% of the times :/')
success = choice([True, False])
if success:
print('I succeed :)')
else:
print('I failed :(')
raise Exception('randomly_failing_task failed!')
def dependent_task():
print('I depend upon the randomly_failing_task.')
print('I am only executed, once the randomly_failing_task succeeded.’)
我问了关于python-rqGitHub项目的问题,该功能现在包含在RQ的1.5.0版中
RQ允许您现在轻松地重试失败的作业。要配置重试,请使用RQ的重试对象,该对象接受
max
和interval
参数依赖作业将保留在延迟作业注册表中,直到它们所依赖的作业成功并仅在此时执行
例如:
以及示例任务:
相关问题 更多 >
编程相关推荐