Celery Task在后端失败时重试

时间:2018-10-03 01:19:16

标签: celery celery-task

我们将芹菜与Redis用作后端,并将RabbitMQ作为代理。我们遇到了一个有趣的场景,我们不清楚如何从中恢复。任务的执行顺序如下:

  1. 芹菜收到任务A进行处理
  2. 任务A已由应用程序成功处理
  3. Celery尝试将“ SUCCESS”作为任务A的结果状态写入Redis
  4. 与redis的连接失败,并引发异常
  5. Celery认为该异常是意外的,并将任务标记为失败

有两件事我们不清楚: 1.如何将此异常标记为可重试。可以说,该异常不在我们任务的执行上下文范围内 2.如果任务A是和弦的一部分,如何确保和弦的回调被调用

P.S .:这是个例外: File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 435, in trace_task uuid, retval, task_request, publish_result, File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 146, in mark_as_done self.on_chord_part_return(request, state, result) File "/usr/local/lib/python2.7/dist-packages/celery/backends/redis.py", line 272, in on_chord_part_return .expire(tkey, self.expires) \ File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2894, in execute return execute(conn, stack, raise_on_error) File "/usr/local/lib/python2.7/dist-packages/redis/client.py", line 2749, in _execute_transaction connection.send_packed_command(all_cmds) File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 585, in send_packed_command self.connect() File "/usr/local/lib/python2.7/dist-packages/redis/connection.py", line 489, in connect raise ConnectionError(self._error_message(e)) ConnectionError: Error -3 connecting to <redis_service>. Temporary failure in name resolution.

0 个答案:

没有答案