celery

Celery详解(3)

北慕城南 提交于 2019-12-06 08:31:12
1.什么是Celery? Celery是一个简单、灵活且可靠的,处理大量消息的分布式系统 专注于实时处理的异步任务队列, 同时也支持任务调度 2.Celery架构 Celery的架构由三部分组成,消息中间件(message broker),任务执行单元(worker)和任务执行结果存储(task result store)组成。 消息中间件 Celery本身不提供消息服务,但是可以方便的和第三方提供的消息中间件集成。包括,RabbitMQ, Redis等等 任务执行单元 Worker是Celery提供的任务执行的单元,worker并发的运行在分布式的系统节点中。 任务结果存储 Task result store用来存储Worker执行的任务的结果,Celery支持以不同方式存储任务的结果,包括AMQP, redis等 执行流程: user相当于提交任务的人,提交给broker也就是消息中间件,worker相当于工人,broker里面有了用户也就是程序提交的任务,worker就去取出来执行类似于生产者消费者模型,store说简单点就是worker执行结束后的返回结果 版本支持情况 Celery version 4.0 runs on Python ❨2.7, 3.4, 3.5❩ PyPy ❨5.4, 5.5❩ This is the last version to support

ECS Airflow 1.10.2 performance issues. Operators and tasks take 10x longer

北慕城南 提交于 2019-12-06 08:25:34
问题 We moved to puckel/Airflow-1.10.2 to try and resolve a poor performance we've had in multiple environments. We are running on ECS Airflow 1.10.2 on AWS ECS. Interestingly, the CPU/mem never jump above 80%. The Airflow metadb stays very underutilized as well. Below I've listed the configuration we're using, the DagBag parsing time plus the detailed execution times from the cProfile output of just running DagBag() in pure Python. A few of our DAGs import a function from create_subdag_functions

Access named volume from container when not running as root?

蹲街弑〆低调 提交于 2019-12-06 08:20:32
问题 I'm running Celery under Docker Compose. I'd like to make Celery's Flower persistent. So I do: version: '2' volumes: [...] flower_data: {} [...] flower: image: [base code image] ports: - "5555:5555" volumes: - flower_data:/flower command: celery -A proj flower --port=5555 --persistent=True --db=/flower/flower However, then I get: IOError: [Errno 13] Permission denied: 'flower.dat' I ran the following to elucidate why: bash -c "ls -al /flower; whoami; celery -A proj flower --persistent=True -

mysql command out of sync when executing insert from celery

 ̄綄美尐妖づ 提交于 2019-12-06 08:18:46
I am running in to the dreaded MySQL Commands out of Sync when using a custom DB library and celery. The library is as follows: import pymysql import pymysql.cursors from furl import furl from flask import current_app class LegacyDB: """Db Legacy Database connectivity library """ def __init__(self,app): with app.app_context(): self.rc = current_app.config['RAVEN'] self.logger = current_app.logger self.data = {} # setup Mysql try: uri = furl(current_app.config['DBCX']) self.dbcx = pymysql.connect( host=uri.host, user=uri.username, passwd=uri.password, db=str(uri.path.segments[0]), port=int(uri

Django Celery and multiple databases (Celery, Django and RabbitMQ)

冷暖自知 提交于 2019-12-06 08:13:34
Is it possible to set a different database to be used with Django Celery? I have a project with multiple databases in configuration and don't want Django Celery to use the default one. I will be nice if I can still use django celery admin pages and read results stored in this different database :) It should be possible to set up a separate database for the django-celery models using Django database routers: https://docs.djangoproject.com/en/1.4/topics/db/multi-db/#automatic-database-routing I haven't tested this specifically with django-celery, but if it doesn't work for some reason, then it's

How can to run task in 5 minutes after finish previous task using celery-beat?

烈酒焚心 提交于 2019-12-06 08:09:35
问题 I have a two tasks - a and b . Task a running in 5 minutes after finish previous task a . Task b running in 3 minutes after finish previous task b . How can I implement it? I'm use python 3.6.8 , Django 2.2.6 and celery 4.3.0 ? 回答1: The short answer is that you can't do this with celery beat because celery beat will trigger off of task start and not at task end. If you absolutely need to do it three minutes after the previous task ends, you'd be advised to just adding a call to .apply_async

Airflow + Cluster + Celery + SQS - Airflow Worker: 'Hub' object has no attribute '_current_http_client'

旧时模样 提交于 2019-12-06 07:11:31
I'm trying to cluster my Airflow setup and I'm using this article to do so. I just configured my airflow.cfg file to use the CeleryExecutor , I pointed my sql_alchemy_conn to my postgresql database that's running on the same master node, I've set the broker_url to use AWS SQS (I didn't set the access_key_id or secret_key since it's running on an EC2-Instance it doesn't need those), and I've set the celery_result_backend to my postgresql server too. I saved my new airflow.cfg changes, I ran airflow initdb , and then I ran airflow scheduler which worked. I went to the UI and turned on one of my

Forking processes for every task in Celery

孤街浪徒 提交于 2019-12-06 06:18:47
问题 I currently use a C extension library for Python, but it seems to have memory leaks. Tasks that are run on my celeryd do something using this C extension library, and celeryd eats a lot of memory about a hour later. I cannot patch this C extension library in many reasons, but instead I want to fork processes for every task in Celery. Are there any such options for Celery? 回答1: You can use CELERYD_MAX_TASKS_PER_CHILD option or --maxtasksperchild celeryd switch. To restart worker processes

How to use priority in celery task.apply_async

。_饼干妹妹 提交于 2019-12-06 05:33:13
问题 I have a test queue in celery and I have defined a task for it: @celery_app.task(queue='test', ignore_result=True) def priority_test(priority): print(priority) which just print the argument.I want to set the priority attribute which is defined here for appy_async . So, I wrote a for loop like this: for i in range(100): priority_test.apply_async((i%10,), queue="test", priority=i%10) I excpected to see some result like this: [2017-12-26 17:21:37,309: WARNING/ForkPoolWorker-1] 10 [2017-12-26 17

How to access the orm with celery tasks?

三世轮回 提交于 2019-12-06 05:16:31
问题 I'm trying to flip a boolean flag for particular types of objects in my database using sqlalchemy+celery beats. But how do I access my orm from the tasks.py file? from models import Book from celery.decorators import periodic_task from application import create_celery_app celery = create_celery_app() # Create celery: http://flask.pocoo.org/docs/0.10/patterns/celery/ # This task works fine @celery.task def celery_send_email(to,subject,template): with current_app.app_context(): msg = Message(