4๐
โ
if you want to fire each call one after another, why dont you wrap all the calls in one task
@task
def make_a_lot_of_calls(numbers):
for num in numbers:
# Assuming that reminder blocks till the call finishes
reminder(number)
def make_calls(request):
make_a_lot_of_calls.delay(phone_numers)
return redirect('live_call_updates')
๐คsrj
39๐
If you look at the celery DOCS on tasks you see that to call a task synchronosuly, you use the apply() method as opposed to the apply_async() method.
So in your case you could use:
reminder.apply(args=[number])
The DOCS also note that:
If the CELERY_ALWAYS_EAGER setting is set, it will be replaced by a local apply() call instead.
Thanks to @JivanAmara who in the comments reiterated that when using apply(), the task will run locally(in the server/computer in which its called). And this can have ramifications, if you intended to run your tasks across multiple servers/machines.
๐คKomu
- [Django]-Sharing django sessions on specific subdomains
- [Django]-Steps to Troubleshoot "django.db.utils.ProgrammingError: permission denied for relation django_migrations"
- [Django]-Django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
3๐
Can use celery chain
.
from celery import chain
tasks = [reminder.s(number) for number in phone_numbers]
chain(*tasks).apply_async()
๐คAbhishake Gupta
- [Django]-Exclude a field from django rest framework serializer
- [Django]-Does SQLAlchemy have an equivalent of Django's get_or_create?
- [Django]-Django: How to write query to sort using multiple columns, display via template
Source:stackexchange.com