celery

Celery 分布式任务队列

一世执手 提交于 2019-12-25 18:17:54
一、Celery介绍和基本使用 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理, 如果你的业务场景中需要用到异步任务,就可以考虑使用celery, 举几个实例场景中可用的例子: 你想对100台机器执行一条批量命令,可能会花很长时间 ,但你不想让你的程序等着结果返回,而是给你返回 一个任务ID,你过一段时间只需要拿着这个任务id就可以拿到任务执行结果, 在任务执行ing进行时,你可以继续做其它的事情。 你想做一个定时任务,比如每天检测一下你们所有客户的资料,如果发现今天 是客户的生日,就给他发个短信祝福 Celery 在执行任务时需要通过一个消息中间件来接收和发送任务消息,以及存储任务结果, 一般使用rabbitMQ or Redis,后面会讲 1.1 Celery有以下优点: 简单:一单熟悉了celery的工作流程后,配置和使用还是比较简单的 高可用:当任务执行失败或执行过程中发生连接中断,celery 会自动尝试重新执行任务 快速:一个单进程的celery每分钟可处理上百万个任务 灵活: 几乎celery的各个组件都可以被扩展及自定制 Celery基本工作流程图 1.2 Celery安装使用 Celery的默认broker是RabbitMQ, 仅需配置一行就可以 broker_url = 'amqp://guest

Celery not queuing tasks to broker on remote server, adds tasks to localhost instead

故事扮演 提交于 2019-12-25 16:42:48
问题 celery.py # set the default Django settings module for the 'celery' program. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings') app = Celery('project', broker='amqp://foo:bar@remoteserver:5672', backend='amqp') # app = Celery('project') # Using a string here means the worker don't have to serialize # the configuration object to child processes. # - namespace='CELERY' means all celery-related configuration keys # should have a `CELERY_` prefix. app.config_from_object('django

Celery error: “No module named billiard.forking” - how to diagnose?

删除回忆录丶 提交于 2019-12-25 05:05:32
问题 I have no idea where to start diagnosing and fixing this: $ bin/django celeryd -l DEBUG -v 3 -------------- celery@lucid32 v3.0.3 (Chiastic Slide) ---- **** ----- --- * *** * -- [Configuration] -- * - **** --- . broker: django://localhost// - ** ---------- . app: default:0x8b0aa4c (djcelery.loaders.DjangoLoader) - ** ---------- . concurrency: 1 (processes) - ** ---------- . events: OFF (enable -E to monitor this worker) - ** ---------- - *** --- * --- [Queues] -- ******* ---- . celery:

Celery/Rabbitmq/Django - Old tasks being executed without being called in my code

天涯浪子 提交于 2019-12-25 03:32:42
问题 I have a simple shared celery task like this: @shared_task def add(): x = barakah(name="add()", year="add()", month="add()") x.save() return "id is add()= " + str(x.id) And I call it here in this CELERYBEAT_SCHEDULE: CELERYBEAT_SCHEDULE = { 'add': { 'task': 'water.tasks.add', 'schedule': timedelta(seconds=3), 'args': () }, } This is the celery command I use: celery -A adi worker -B -l info It runs fine as per schedule but other old tasks are also executing as well. How do I stop the old tasks

Celery keeps creating rabbitmq queues, pilling all over

冷暖自知 提交于 2019-12-25 03:28:09
问题 Using celery (3.1.8 + ) with django 1.6 all tasks are defined to ignore results (is this the correct syntax?) @shared_task(ignore_result=True) def somefunc(): pass When I look at the rabbitmq queues I see more and more queues created by celery with names like: 19926fa9965e40c19ed9640c2b42ce1e and contain one message (similar to the following): correlation_id: 19926fa9-965e-40c1-9ed9-640c2b42ce1e priority: 0 delivery_mode: 2 headers: content_encoding: binary content_type: application/x-python

django 2.1 celery not execute asyncron task

早过忘川 提交于 2019-12-24 23:32:22
问题 i try to execute background function using celery: this is my current code : from VideoPublish.models import TitleVideo, Videos from celery.decorators import task from UploadExpert.celery import app # Create your views here. demo_titles =['title1', 'title2', 'title3'] @app.task(ignore_result=True) def GetTitles(video_id): video = Videos.objects.get(pk=video_id) for title in demo_titles: t = TitleVideo( title=title, video_id=video.id ) t.save() this is call function : GetTitles.delay(video_id

consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 61] Connection refused

为君一笑 提交于 2019-12-24 20:02:40
问题 This is my project structure myproj │ ├── app1 ├── __init__.py ├── tasks.py |---gettingstarted ├── __init__.py ├── urls.py ├── settings.py │ ├── manage.py |-- Procfile In gettingstarted/settings: BROKER_URL = 'redis://' In Procfile: web: gunicorn gettingstarted.wsgi --log-file - worker: celery worker --app=app1.tasks.app In app1/tasks.py from __future__ import absolute_import, unicode_literals import random import celery import os app = celery.Celery('hello') @app.task def add(x, y): return x

Apps aren't loaded yet when trying to import model in a celery tasks file

假装没事ソ 提交于 2019-12-24 19:06:53
问题 Before any explanations, here is the tree of my project | projectname |____|__init__.py |____|celery.py |____|settings.py |____|urls.py |____|wsgi.py |app1 |app2 Here's my celery.py from celery import Celery from celery import shared_task os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings') app = Celery('projectname') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks() from app1.models import * @share_task def tasks(): ''' ''' Every

Accessing `http://localhost:8080/admin/djcelery/` returns 403 in Django

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 14:28:55
问题 I am trying to access http://localhost:8080/admin/djcelery/ in my Django admin. I can access http://localhost:8080/admin , I can run celery task but I can't access the djcelery admin site. Here is my url url(r'^admin/', include(admin.site.urls)), Here is settings.py import djcelery djcelery.setup_loader() BROKER_URL = "amqp://guest:guest@localhost:5672//" CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend' CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' Do I have

How can I get rid of legacy tasks still in the Celery / RabbitMQ queue?

醉酒当歌 提交于 2019-12-24 08:26:09
问题 I am running Django + Celery + RabbitMQ. After modifying some task names I started getting "unregistered task" KeyErrors, even after removing tasks with this key from the Periodic tasks table in Django Celery Beat and restarting the Celery worker. They persist even after running with the --purge option. How can I get rid of them? 回答1: To flush out the last of these tasks, you can re-implement them with their old method headers, but no logic. For example, if you removed the method original and