You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
"""
|
|
|
|
Many resources on the web recommend using celery.task. This might cause circular imports since you'll have to import the Celery instance.
|
|
|
|
We used shared_task to make our code reusable, which, again, requires current_app in create_celery instead of creating a new Celery instance.
|
|
|
|
Now, we can copy this file anywhere in the app and it will work as expected.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from celery import shared_task
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def divide(x, y):
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
time.sleep(5)
|
|
|
|
return x / y
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
def add(x, y):
|
|
|
|
import time
|
|
|
|
|
|
|
|
time.sleep(5)
|
|
|
|
return x + y
|