gpt4 book ai didi

python - 如何在 Python 中正确捕获和处理 RQ 超时?

转载 作者:IT王子 更新时间:2023-10-29 05:56:55 25 4
gpt4 key购买 nike

试图找到一种捕捉 RQ 超时的好方法作业,因此可以在超时后重新排队。

基本上,正确的解决方案将提供一种方法(例如,工作程序中的异常处理程序或类似的东西)来重新排队超时的作业。此外,如果作业返回到 failed 队列,这也是一个很好的答案。

非常感谢!任何帮助将不胜感激!

最佳答案

听起来您想使用 exception handling .来自文档:

Jobs can fail due to exceptions occurring. When your RQ workers run in the background, how do you get notified of these exceptions?

Default: the failed queue The default safety net for RQ is the failed queue. Every job that fails execution is stored in here, along with its exception information (type, value, traceback). While this makes sure no failing jobs "get lost", this is of no use to get notified pro-actively about job failure.

Custom exception handlers Starting from version 0.3.1, RQ supports registering custom exception handlers. This makes it possible to replace the default behaviour (sending the job to the failed queue) altogether, or to take additional steps when an exception occurs.

您还可以将作业存储在以 job_id 为键,以 time.time() + timeout 为分数的 redis 排序集中,然后让工作人员运行 ZRANGEBYSCORE sorted_set 0 [current_time] 并处理作为超时作业返回的任何内容。

关于python - 如何在 Python 中正确捕获和处理 RQ 超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18644632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com