M
M
Maxim2016-11-18 18:04:23
Django
Maxim, 2016-11-18 18:04:23

How to view task results in celery?

Need help understanding how celery works, especially how to monitor execution of
Celery 4.0 + redis
1 tasks.

from celery import shared_task
from celery.decorators import task
from celery.utils.log import get_task_logger

logger = get_task_logger(__name__)

@shared_task
def add(x, y):
    logger.info('adding')
    return x + y

There is a task for an example in which logging is implemented, but the log is displayed only with such a call when there is silence in the console, why and how to display all twitching tasks in the console? 2.
add.delay(2,2)
add(2,2)
@periodic_task(
     run_every=(crontab(minute='*/1')),
     ignore_result=True
 )
 def period():
     req = requests.get('http://example')
     req = message_delayed()
     send(req)
     logger.info('task success')

With a periodic task, all actions are always logged in the console, is it possible to achieve the same result with
@task
these 2 questions, in principle, can be combined, it’s only interesting why you
@periodic_task
don’t need to write
3 for anything additional.
@csrf_exempt
@task
def user_get(request):
    if request.method == 'POST':

There is a usual function wrapped with a task, it is written in the docks that the task decorator must go before all decorators, but in such cases, django swears that there is no @csrf, is it correct to use it like that? Or maybe there are other options?
4. Perhaps tell me how to display all the logs in a file for celery 4.0? the whole procedure is not entirely clear
5. I would also like to understand redis, in fact it should record all tasks?
I looked at the contents through keys * and after the task was completed, the contents did not change (there are only about 7 of them), because it can not be like that.
I am only superficially familiar with celery and I will be grateful for all the answers / advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Innokentiev, 2016-11-18
@artinnok

flower will help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question