2

I created a celery shared_task which executes another shared_task:

@shared_task(base=WorkerBase,
             name='analytics.worker-tenant',
             rate_limit='3/m')
def worker_tenant():
    tenants = Tenant.objects.values_list('id', 'contexttenant')

    print('first:worker_tenant')
    for tenant in tenants:
        worker_update_tenant.delay(tenant[0], tenant[1])


@shared_task(name='analytics.worker-update-tenant',
             autoretry_for=(HTTPError, ConnectionError),
             retry_backoff=True)
def worker_update_tenant(id, context, timespan=timedelta(weeks=1)):
    print('worker_update_tenant')

I get the output of the first print first:worker_tenant but not the second one worker_update_tenant.

I have also tried to call the second task with apply_async(args=(...)) but that also didn't work!

wasp256
  • 5,943
  • 12
  • 72
  • 119

1 Answers1

0

I managed to get it to work by using a generator with group instead:

group(
    worker_update_tenant.s(tenant[0], tenant[1]) for tenant in tenants
).apply_async()
wasp256
  • 5,943
  • 12
  • 72
  • 119