我有一个从网络服务器下载资源的 Python RQ 作业。
如果网络服务器无响应,下载作业是否可以自行重新安排并在一定时间间隔后重试下载?
多个转换作业依赖于下载作业
job_queue.enqueue(transformation_task, depends_on=download_job)
如果下载作业可以自行重新安排,那么相关作业是否会保留下来,并在下载作业完成后最终执行?
我在python-rq GitHub 项目上提出了这个问题,该功能现已包含在 RQ 的 1.5.0 版本中。
\nRQ 现在可以让您轻松重试失败的作业。max要配置重试,请使用接受和参数的 RQ\xe2\x80\x99s Retry 对象interval。
相关作业将保留在延迟作业注册表中,直到它们所依赖的作业成功并才执行。
\n例如:
\nfrom redis import Redis\nfrom rq import Queue, Retry\nfrom somewhere import randomly_failing_task, dependent_task\n\njob_queue = Queue(connection=Redis())\nrandomly_failing_job = job_queue.enqueue(randomly_failing_task, retry=Retry(max=3))\ndependent_job = job_queue.enqueue(dependent_task, depends_on=randomly_failing_job)\nRun Code Online (Sandbox Code Playgroud)\n以及示例任务:
\nfrom random import choice\n\ndef randomly_failing_task():\n print(\'I am a task, I will fail 50% of the times :/\')\n success = choice([True, False])\n if success:\n print(\'I succeed :)\')\n else:\n print(\'I failed :(\')\n raise Exception(\'randomly_failing_task failed!\')\n\n\ndef dependent_task():\n print(\'I depend upon the randomly_failing_task.\')\n print(\'I am only executed, once the randomly_failing_task succeeded.\xe2\x80\x99)\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1316 次 |
| 最近记录: |