Python RQ 作业可以重新安排自身并保持依赖作业吗?

Mar*_*inW 1 python python-rq

我有一个从网络服务器下载资源的 Python RQ 作业。

  1. 如果网络服务器无响应,下载作业是否可以自行重新安排并在一定时间间隔后重试下载?

  2. 多个转换作业依赖于下载作业

    job_queue.enqueue(transformation_task, depends_on=download_job)

    如果下载作业可以自行重新安排,那么相关作业是否会保留下来,并在下载作业完成后最终执行?

Mar*_*inW 5

GitHub 项目上提出了这个问题,该功能现已包含在 RQ 的 1.5.0 版本中。

\n
    \n
  1. RQ 现在可以让您轻松重试失败的作业。max要配置重试,请使用接受和参数的 RQ\xe2\x80\x99s Retry 对象interval

    \n
  2. \n
  3. 相关作业将保留在延迟作业注册表中,直到它们所依赖的作业成功并才执行。

    \n
  4. \n
\n

例如:

\n
from 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)\n
Run Code Online (Sandbox Code Playgroud)\n

以及示例任务:

\n
from 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)\n
Run Code Online (Sandbox Code Playgroud)\n