celery

Celery定时任务细讲

纵饮孤独 提交于 2019-12-01 06:59:10
一.目录结构 任务所在目录 ├── celery_task # celery包 如果celery_task只是建了普通文件夹__init__可以没有,如果是包一定要有 │ ├── __init__.py # 包文件 看情况要不要存在 │ ├── celery.py # celery连接和配置相关文件,且名字必须交celery.py,其实也不是必须的不然你指令可能要修改 │ └── tasks.py # 所有任务函数 二.配置 celery.py from celery import Celery #创建一个Celery对象 broker = 'redis://127.0.0.1:6379/2' #任务放在用redis://ip:端口/第几个数据库 backend = 'redis://127.0.0.1:6379/3' #任务结果放在 include = ['celery_task.tasks',] #任务所在目录 app = Celery(broker=broker, backend=backend, include=include) app.conf.timezone = 'Asia/Shanghai' #配置时区 app.conf.enable_utc = False # 是否使用UTC from datetime import timedelta from celery

Celery error : result.get times out

◇◆丶佛笑我妖孽 提交于 2019-12-01 06:55:07
I've installed Celery and I'm trying to test it with the Celery First Steps Doc . I tried using both Redis and RabbitMQ as brokers and backends, but I can't get the result with : result.get(timeout = 10) Each time, I get this error : Traceback (most recent call last): File "<input>", line 11, in <module> File "/home/mehdi/.virtualenvs/python3/lib/python3.4/site-packages/celery/result.py", line 169, in get no_ack=no_ack, File "/home/mehdi/.virtualenvs/python3/lib/python3.4/site-packages/celery/backends/base.py", line 225, in wait_for raise TimeoutError('The operation timed out.') celery

celery4.0版本

岁酱吖の 提交于 2019-12-01 06:08:57
大写的命名空间意味着所有芹菜配置必须用大写而不是小写来指定,并以 CELERY_ 开始,因此,例如, task_always_eager 设置成为 CELERY_TASK_ALWAYS_EAGER , broker_url 成为 CELERY_BROKER_URL ans等等。这个配置是从celery4.0开始引入的。 因此,对于version <4,不需要在行中使用 namespace : app.config_from_object('django.conf:settings', namespace='CELERY') 将上述资料改为: app.config_from_object('django.conf:settings') 来源: https://www.cnblogs.com/xingkongzhizhu/p/11664099.html

celery 'Worker-n' pid:xxxx exited with 'exitcode 1' when I import hmmlearn

寵の児 提交于 2019-12-01 05:18:39
问题 In my tasks.py file, when I import hmmlearn, from hmmlearn import hmm and start my celery workers, I get the following error [2017-06-14 09:18:27,638: INFO/MainProcess] Received task: sm.tasks.mytask[4e46806e-6f0f-420f-baac-c727c2a382d4] [2017-06-14 09:18:27,716: ERROR/MainProcess] Process 'Worker-4' pid:5264 exited with 'exitcode 1' [2017-06-14 09:18:29,857: ERROR/MainProcess] Process 'Worker-7' pid:3172 exited with 'exitcode 1' [2017-06-14 09:18:29,857: ERROR/MainProcess] Process 'Worker-6'

Does the number of celeryd processes depend on the --concurrency setting?

£可爱£侵袭症+ 提交于 2019-12-01 05:13:50
We are running Celery behind Supervisor and start it with celeryd --events --loglevel=INFO --concurrency=2 This, however, creates a process graph that is up to three layers deep and contains up to 7 celeryd processes (Supervisor spawns one celeryd, which spawns several others, which again spawn processes). Our machine has two CPU cores. Are all of these processes working on tasks? Are maybe some of them just worker pools? How is the --concurrency setting connected to the number of processes actually spawned? You shouldn't have 7 processes if --concurrency is 2. The actual processes started is:

python任务调度模块celery

别来无恙 提交于 2019-12-01 05:11:00
python任务调度模块celery celery简介 Celery是一个python开发的异步分布式任务调度模块。 Celery本身并不提供消息服务,使用第三方服务,也就是borker来传递任务,一般使用rabbitMQ或者Redis。 Celery特点 简单:一单熟悉了celery的工作流程后,配置和使用还是比较简单的。 高可用:当任务执行失败或执行过程中发生连接中断,celery 会自动尝试重新执行任务。 快速:一个单进程的celery每分钟可处理上百万个任务。 灵活: 几乎celery的各个组件都可以被扩展及自定制。 Celery工作流程图 python-Celery celery安装使用 安装Celery模块 1 pip install celery Celery的默认broker是RabbitMQ,仅需配置一行 1 broker_url = 'amqp://guest:guest@localhost:5672//' RabbitMQ的安装点击 Using RabbitMQ 查看。 redis作为broker也可以。 安装 1 pip install redis 配置 broker_url配置redis数据库地址,格式为 redis://:password@hostname:port/db_number 。 backend配置任务结果存储位置,将保存每个任务的执行结果。

在django中使用Celery 和 Celery-Flower

∥☆過路亽.° 提交于 2019-12-01 05:10:47
在django中使用Celery 和 Celery-Flower 1、Celery方式的选择 这里Celery的中间人,我采用Redis。也可以用Django自身和mongodb等。Celery的中间人你可以理解为在Celery执行过程中的数据支持。保存列队记录、执行记录等等。安装Redis,可参考Redis在CentOS和Windows安装过程。 安装redis brew install redis 安装celery-with-redis,执行命令: pip install celery-with-redis 该命令会自动安装redis(python库)、celery、kombu、billiard、amqp、vine和celery-with-redis相关库。注意,这里pip安装的redis是python操作redis的库,非redis数据库。redis数据库需要独立安装。 2、Django加入Celery 打开settings.py所在的文件夹,新建celery.py文件。加入如下代码 from __future__ import absolute_import, unicode_literals from celery import Celery from django.conf import settings from os import path, environ

分布式任务队列Celery快速上手

六月ゝ 毕业季﹏ 提交于 2019-12-01 05:10:33
Celery介绍 celery(芹菜)是一个异步任务队列/基于分布式消息传递的作业队列。 它侧重于实时操作,但对调度支持也很好。 celery用于生产系统每天处理数以百万计的任务。 celery是用Python编写的,但该协议可以在任何语言实现。它也可以用其他语言通过webhooks实现。 目前已知有php/ruby/nodejs的实现 为什么用Celery? 异步 耗时久的事儿可以扔给 Worker 处理,处理完可以触发子任务提醒 天然的并发能力(多进程/协程)! 非常方便添加 Worker 来增强处理能力 Celery提供了Web方式的监控/报警,这样,我们就可以监控每个任务的情况了 出现错误可以自动处理/重试 角色介绍 Brokers : 提供队列服务,Celery支持的Brokers有: RabbitMQ( 推荐 ) Redis MongoDB Beanstalk CouchDB SQLAlchemy(MySQL/PostgreSQL/Sqlite/Oracle) Amazon SQS等 Worker : 真正干活的,实际运行任务的节点。 开始 Celery 的第一步 选择你的 Broker 在你正式开始使用 Celery 之前,你需要选择、安装并运行一个 broker。 Broker 是一种负责接收、发送任务消息(task messages)的服务 你可以从以下几种

并行处理框架Celery的Web监控管理服务-Flower

三世轮回 提交于 2019-12-01 05:08:32
Flower: Real-time Celery web-monitor Flower是Celery的一个实时监控和管理Web界面工具,目前仍在活跃的开发之中,但已经是一个很重要的可用工具了。这是推荐使用的Celery监控工具,原来的基于Django-Admin monitor、celerymon、ncurses的监控管理已经过时。 Flower在快速的开发和变化之中, 你也可以得到相对稳定的版本。 Features 使用Celery Events进行实时监视 Task进度和历史。 显示task详细信息 (参数,启动时间,运行时间,其它...) 统计数据和图形表示。 远程控制 查看worker状态和统计信息。 关闭和重启worker实例。 控制worker池的大小和自动伸缩的设置。 查看和修改worker实例消费的队列。 查看当前运行的任务。 查看 tasks的调度 (ETA/countdown)。 查看保留和重新唤醒的tasks。 应用实践和频度限制。 配置的查看。 唤醒和终止tasks。 HTTP的 API接口。 OpenID鉴权方法。 运行的截屏: More screenshots : 安装和使用 使用pip安装Flower: $ pip install flower #如果没有pip,使用sudo apt-get install python-pip进行安装。 运行

Celery Result backend. DisabledBackend object has no attribute _get_task_meta_for

泄露秘密 提交于 2019-12-01 04:58:25
I have configured celery and the backend: cleryapp = Celery( 'tasks_app', brocker='amqp://guest@localhost//', backend='db+postgresql://guest@localhost:5432' ) 'results' appears disabled when i start the worker, but I read on another question here that that's not the issue. The database is getting all the data correctly, but result = AsyncResult(task_id) raises AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for' I found a more convenient way to do that. result = celery.AsyncResult(task_id) celery is the Celery instance of your application, not the celery module. try