Skip to content Skip to sidebar Skip to footer

Python Celery - How To Call Celery Tasks Inside Other Task

I'm calling a task within a tasks in Django-Celery Here are my tasks. @shared_task def post_notification(data,url): url = 'http://posttestserver.com/data/?dir=praful' # when in

Solution 1:

This should work:

celery.current_app.send_task('mymodel.tasks.mytask', args=[arg1, arg2, arg3])

Solution 2:

You are right, because each task in you for loop will be overwrite task variable.

You can try celery.group like

from celery import group

and

@shared_task
def shipment_server(data,notification_type):
    notification_obj = Notification.objects.get(name = notification_type)
    server_list = ServerNotificationMapping.objects.filter(notification_name=notification_obj)


    tasks = [post_notification.s(data, server.server_id.url) for server in server_list]
    results = group(tasks)()
    print results.get() # results.status() what ever you want

Solution 3:

you can call task from a task using delay function

from app.tasks import celery_add_task
    celery_add_task.apply_async(args=[task_name]) 

... it will work


Post a Comment for "Python Celery - How To Call Celery Tasks Inside Other Task"