Michael Neale
Michael Neale

Reputation: 19468

Retry with celery Http Callback Tasks

I looking at the http callback tasks - http://celeryproject.org/docs/userguide/remote-tasks.html in celery. They work well enough when the remote endpoint is available - but when it is unavailable I would like it to retry (as per retry policy) - or even if the remote endpoint returns a failure. at the moment it seems to be an error and the task is ignored.

Any ideas ?

Upvotes: 0

Views: 983

Answers (1)

Doug-W
Doug-W

Reputation: 1328

You should be able to define your task like:

class RemoteCall(Task):
    default_retry_delay = 30 * 60 # retry in 30 minutes

    def Run(self, arg, **kwargs):
        try:
            res = URL("http://example.com/").get_async(arg)
        except (InvalidResponseError, RemoteExecuteError), exc:
            self.retry([arg], exc=exc, *kwargs)

This will keep trying it up to max_retries tries, once every 30 minutes.

Upvotes: 1

Related Questions