Answer the question
In order to leave comments, you need to log in
How to know if celery is executing a function asynchronously?
I am attaching celery settings
# settings.py
# CELERY STUFF
BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
# celery.py
from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings
#
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
app = Celery('backend')
#
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
# tasks.py
import json
import requests
from celery.decorators import task
from celery.task.schedules import crontab
from celery.decorators import periodic_task
from celery.utils.log import get_task_logger
from api.controllers.message import message_delayed
logger = get_task_logger(__name__)
@periodic_task(
run_every=(crontab(minute='*/1')),
ignore_result=True
)
def period():
# req = requests.get('')
req = message_delayed()
send(req)
logger.info('task success')
@task
def send(mes):
print('it works')
# do_something
[tasks]
. api.tasks.period
. api.tasks.send
. api.views.user_get
. backend.celery.debug_task
Answer the question
In order to leave comments, you need to log in
I don’t know what other settings you have there and what tasks but try this:
CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
BROKER_URL='django://'
but in production you need to (correctly) use another broker, for example: RabbitMQ, Redis ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question