I' ve got a bunch of tasks in Celery all connected using a canvas chain
.
@shared_task(bind=True)
def my_task_A(self):
try:
logger.debug('running task A')
do something
except Exception:
run common cleanup function
@shared_task(bind=True)
def my_task_B(self):
try:
logger.debug('running task B')
do something else
except Exception:
run common cleanup function
...
So far so good. The problem is that I'm looking for the best practice when it comes to using a common utility function like this:
def cleanup_and_notify_user(task_data):
logger.debug('task failed')
send email
delete folders
...
What't the best way to do that without the tasks blocking?
For example can I just replace run common cleanup function
with a call to cleanup_and_notify_user(task_data)
? And what would happen if multiple tasks from multiple workers attempt to call that function at the same time?
Does each worker get its own copy? I apparently am a bit confused over few of the concepts here. Any help is much appreciated.
Thank you all in advance.