Bojan Jovanovic
Bojan Jovanovic

Reputation: 1499

In Django Celery how can I tell if a task has been executed asynchronously

how can I tell from within a celery task, if the task has been called from just the apply method, rather then the apply_async ( or delay ).

Upvotes: 3

Views: 2059

Answers (1)

Simeon Visser
Simeon Visser

Reputation: 122376

You can look at the is_eager or called_directly attributes of self.request within the task (the documentation currently isn't very clear on the difference):

@app.task(bind=True)
def task_with_context(self, *args, **kwargs):
    print self.request.is_eager, self.request.called_directly

Upvotes: 11

Related Questions