django-celery

django celery: how to set task to run at specific interval programmatically

半腔热情 提交于 2019-11-29 14:42:30
问题 I found that I can set the task to run at specific interval at specific times from here, but that was only done during task declaration. How do I set a task to run periodically dynamically? 回答1: The schedule is derived from a setting, and thus seems to be immutable at runtime. You can probably accomplish what you're looking for using Task ETAs. This guarantees that your task won't run before the desired time, but doesn't promise to run the task at the designated time—if the workers are

Retrying celery failed tasks that are part of a chain

天涯浪子 提交于 2019-11-29 05:45:14
I have a celery chain that runs some tasks. Each of the tasks can fail and be retried. Please see below for a quick example: from celery import task @task(ignore_result=True) def add(x, y, fail=True): try: if fail: raise Exception('Ugly exception.') print '%d + %d = %d' % (x, y, x+y) except Exception as e: raise add.retry(args=(x, y, False), exc=e, countdown=10) @task(ignore_result=True) def mul(x, y): print '%d * %d = %d' % (x, y, x*y) and the chain: from celery.canvas import chain chain(add.si(1, 2), mul.si(3, 4)).apply_async() Running the two tasks (and assuming that nothing fails), your

How can I disable the Django Celery admin modules?

旧城冷巷雨未停 提交于 2019-11-29 03:20:54
问题 I have no need to the celery modules in my Django admin. Is there a way I could remove it? 回答1: To be more specific, in admin.py of any app inside INSTALLED_APPS after 'djcelery' from django.contrib import admin from djcelery.models import ( TaskState, WorkerState, PeriodicTask, IntervalSchedule, CrontabSchedule) admin.site.unregister(TaskState) admin.site.unregister(WorkerState) admin.site.unregister(IntervalSchedule) admin.site.unregister(CrontabSchedule) admin.site.unregister(PeriodicTask)

How to monitor events from workers in a Celery-Django application?

旧城冷巷雨未停 提交于 2019-11-29 01:21:11
问题 According to the celery tutorial regarding real-time monitoring of celery workers, one can also programmatically capture the events produced by the workers and take action accordingly. My question is how can I integrate a monitor as the one in this example, in a Celery-Django application? EDIT: The code example in the tutorial looks like: from celery import Celery def my_monitor(app): state = app.events.State() def announce_failed_tasks(event): state.event(event) task_id = event['uuid'] print

Django and Celery - re-loading code into Celery after a change

为君一笑 提交于 2019-11-28 23:14:30
If I make a change to tasks.py while celery is running, is there a mechanism by which it can re-load the updated code? or do I have to shut Celery down a re-load? I read celery had an --autoreload argument in older versions, but I can't find it in the current version: celery: error: unrecognized arguments: --autoreload ChillarAnand Unfortunately --autoreload doesn't work and it is deprecated . You can use Watchdog which provides watchmedo a shell utilitiy to perform actions based on file events. pip install watchdog You can start worker with watchmedo auto-restart -- celery worker -l info -A

How to write an Ubuntu Upstart job for Celery (django-celery) in a virtualenv

℡╲_俬逩灬. 提交于 2019-11-28 18:52:25
I really enjoy using upstart. I currently have upstart jobs to run different gunicorn instances in a number of virtualenvs. However, the 2-3 examples I found for Celery upstart scripts on the interwebs don't work for me. So, with the following variables, how would I write an Upstart job to run django-celery in a virtualenv. Path to Django Project: /srv/projects/django_project Path to this project's virtualenv: /srv/environments/django_project Path to celery settings is the Django project settings file (django-celery): /srv/projects/django_project/settings.py Path to the log file for this

Django-Celery progress bar

老子叫甜甜 提交于 2019-11-28 17:05:56
I use: Celery Django-Celery RabbitMQ I can see all my tasks in the Django admin page, but at the moment it has just a few states, like: RECEIVED RETRY REVOKED SUCCESS STARTED FAILURE PENDING It's not enough information for me. Is it possible to add more details about a running process to the admin page? Like progress bar or finished jobs counter etc. I know how to use the Celery logging function, but a GUI is better in my case for some reasons. So, is it possible to send some tracing information to the Django-Celery admin page? I am starting to try figuring this out myself. Start by defining a

Detect whether Celery is Available/Running

烈酒焚心 提交于 2019-11-28 16:49:42
I'm using Celery to manage asynchronous tasks. Occasionally, however, the celery process goes down which causes none of the tasks to get executed. I would like to be able to check the status of celery and make sure everything is working fine, and if I detect any problems display an error message to the user. From the Celery Worker documentation it looks like I might be able to use ping or inspect for this, but ping feels hacky and it's not clear exactly how inspect is meant to be used (if inspect().registered() is empty?). Any guidance on this would be appreciated. Basically what I'm looking

Add n tasks to celery queue and wait for the results

こ雲淡風輕ζ 提交于 2019-11-28 07:26:09
I would add multiple tasks to celery queue and wait for results. I have various ideas how I would achieve this utilising some form of shared storage (memcached, redis, db, etc.), however, I would have thought it's something that Celery can handle automatically but I can't find any resources online. Code example def do_tasks(b): for a in b: c.delay(a) return c.all_results_some_how() laffuste For Celery >= 3.0 , TaskSet is deprecated in favour of group . from celery import group from tasks import add job = group([ add.s(2, 2), add.s(4, 4), add.s(8, 8), add.s(16, 16), add.s(32, 32), ]) Start the

Stopping/Purging Periodic Tasks in Django-Celery

走远了吗. 提交于 2019-11-28 06:06:24
I have managed to get periodic tasks working in django-celery by subclassing PeriodicTask. I tried to create a test task and set it running doing something useless. It works. Now I can't stop it. I've read the documentation and I cannot find out how to remove the task from the execution queue. I have tried using celeryctl and using the shell, but registry.tasks() is empty, so I can't see how to remove it. I have seen suggestions that I should "revoke" it, but for this I appear to need a task id, and I can't see how I would find the task id. Thanks. A task is a message, and a "periodic task"