celery

Python / Celery : how can I kill subtasks when killing a parent task?

坚强是说给别人听的谎言 提交于 2020-03-01 05:43:25
问题 Context I've created a Django application that is calling a celery task which in turns spawn other tasks and wait for them to be finished. Here's the workflow : 1) The main python/django code start a celery task in the background 2) The celery task process some code and then start a celery group of differents tasks and wait for them to be ready 3) every task of the group then spawn another group of subtasks in the same way and wait for them to finish It works well (although I'm a begginer and

Celery如何使用与项目实践

北城余情 提交于 2020-03-01 02:52:45
一. Celery介绍 参考博客:http://www.cnblogs.com/alex3714/p/6351797.html 1、celery应用举例 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以轻松的实现任务的异步处理,如果你的业务场景中需要用到异步任务,就可以考虑使用celery 你想对100台机器执行一条批量命令,可能会花很长时间 ,但你不想让你的程序等着结果返回,而是给你返回 一个任务ID,你过一段时间只需要拿着这个任务id就可以拿到任务执行结果, 在任务执行ing进行时,你可以继续做其它的事情 Celery 在执行任务时需要通过一个消息中间件来接收和发送任务消息,以及存储任务结果, 一般使用rabbitMQ or Redis 2、Celery有以下优点 简单:一单熟悉了celery的工作流程后,配置和使用还是比较简单的 高可用:当任务执行失败或执行过程中发生连接中断,celery 会自动尝试重新执行任务 快速:一个单进程的celery每分钟可处理上百万个任务 灵活: 几乎celery的各个组件都可以被扩展及自定制 3、Celery基本工作流程图 user:用户程序,用于告知celery去执行一个任务。 broker: 存放任务(依赖RabbitMQ或Redis,进行存储) worker:执行任务 二. celery简单使用 1、安装

Could someone please clarify the task priority usage in Celery tasks?

こ雲淡風輕ζ 提交于 2020-03-01 02:34:00
问题 The documentation says very little about the priority attribute. One of the rare documentation references says the following: priority (int): The task priority, a number between 0 and 9. Defaults to the :attr:`priority` attribute. (Ref: http://docs.celeryproject.org/en/latest/_modules/celery/app/task.html#Task.apply_async ) However, if you go to the bottom of the following page - http://docs.celeryproject.org/en/latest/userguide/calling.html - you will see: priority A number between 0 and 255

【翻译】在开公司之前, 我希望知道的关于Django的11件事

坚强是说给别人听的谎言 提交于 2020-02-29 16:50:07
两年前, 我开了家公司SocialQ。在开这家公司之前, 我几乎对开发一无所知。 我从头学习了HTTP, javascript, AJAX, 以及 Django 的MVC。 这是一个疯狂的旅程, 我们的知识栈 从成熟的技术到一些有趣的技术, 比如 D3.js, Backbone.js, Celery,Mongo, Redis, 以及其他的一些, 但这些不是一朝一夕的事情, 看看每天数千行的Django 代码, 我想把我本来可以做却没有做的事情点出来是必要的(I thought it would be worth pointing out things I wish I did differently。 按我自己从全文的理解意译的 译者注): 1. 从正确的目录结构开始: 开始, 我看了一些开源的工程作为指导, 读了一些博客, 但是想不到一个好的方式组织Django工程。下面是我目前使用的结构: apps 目录用于存放一些自定义的Django apps, vendor 目录用于存放一些你不想通过pip 或者easy_install安装的apps。 bin 目录存放所有bash脚本,用于自动化部署。我在这里边有一些脚本用于部署到stage produection 服务器, 清理目录, 压缩资料(asserts), 备份数据库, 启动/停止 celery(本地)等等。 config

Celery的基本使用

ぃ、小莉子 提交于 2020-02-28 17:59:01
Celery 1、什么是Celery Celery是一个简单、灵活且可靠的,处理大量消息的分布式系统,专注于实时处理的异步任务队列,同时也支持任务调度。 用Python写的执行 定时任务和异步任务的框架 执行异步任务: 创建任务:tasks.py 把任务添加到队列中:add_task.py 开启work,执行任务 用命令:celery -A tasks worker -l info 在 Windows下:celery -A tasks worker -l info -P eventlet 查看任务结果:task_resut.py 多任务结构: 重点:执行work的时候:celery -A tasks worker -l info -P eventlet 2、Celery架构 Celery的架构由三部分组成,消息中间件,任务执行单元和任务执行结果存储(task result store )组成。 消息中间件 Celery本身不提供消息服务,但是可以方便的和第三方提供的消息中间件集成。包括,RabbitMQ, Redis等等 任务执行单元 Worker是Celery提供的任务执行的单元,worker并发的运行在分布式的系统节点中。 任务结果存储 Task result store用来存储Worker执行的任务的结果,Celery支持以不同方式存储任务的结果,包括AMQP, redis等

Django with Celery - existing object not found

孤人 提交于 2020-02-28 06:34:46
问题 I am having problem with executing celery task from another celery task. Here is the problematic snippet (data object already exists in database, its attributes are just updated inside finalize_data function): def finalize_data(data): data = update_statistics(data) data.save() from apps.datas.tasks import optimize_data optimize_data.delay(data.pk) @shared_task def optimize_data(data_pk): data = Data.objects.get(pk=data_pk) #Do something with data Get call in optimize_data function fails with

Django with Celery - existing object not found

末鹿安然 提交于 2020-02-28 06:34:09
问题 I am having problem with executing celery task from another celery task. Here is the problematic snippet (data object already exists in database, its attributes are just updated inside finalize_data function): def finalize_data(data): data = update_statistics(data) data.save() from apps.datas.tasks import optimize_data optimize_data.delay(data.pk) @shared_task def optimize_data(data_pk): data = Data.objects.get(pk=data_pk) #Do something with data Get call in optimize_data function fails with

Django with Celery - existing object not found

空扰寡人 提交于 2020-02-28 06:34:07
问题 I am having problem with executing celery task from another celery task. Here is the problematic snippet (data object already exists in database, its attributes are just updated inside finalize_data function): def finalize_data(data): data = update_statistics(data) data.save() from apps.datas.tasks import optimize_data optimize_data.delay(data.pk) @shared_task def optimize_data(data_pk): data = Data.objects.get(pk=data_pk) #Do something with data Get call in optimize_data function fails with

python教程:python基于celery实现异步任务周期任务定时任务

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-28 03:31:19
这篇文章主要介绍了python基于celery实现异步任务周期任务定时任务,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 hello, 小伙伴们, 好久不更新了,这一次带来的是celery在python中的应用以及设置异步任务周期任务和定时任务的步骤,希望能给入坑的你带来些许帮助. 首先是对celery的介绍,Celery其实是一个专注于实时处理和调度任务的分布式任务队列,同时提供操作和维护分布式系统所需要的全部数据, 因此可以用它提供的接口快速实现并管理一个分布式的任务队列,它本身不是任务队列,它是封装了操作常见任务队列的各种操作, 可以使用它快速进行任务队列的使用与管理.在Python中的组成部分是 1.用户任务 app 2.管道 broker 用于存储任务 官方推荐的是 redis rabbitMQ / backend 用于存储任务执行结果的 3, 员工 worker 大致流程入下: 最左边的是用户, 用户发起1个请求给服务器, 要服务器执行10个任务,将这10个任务分给10个调度器,即开启10个线程进行任务处理,worker会一直监听调度器是否有任务, 一旦发现有新的任务, 就会立即执行新任务,一旦执行完就会返回给调度器, 即backend, backend会将请求发送给服务器, 服务器将结果返回给用户, 表现的结果就是

Celery Beat: Limit to single task instance at a time

耗尽温柔 提交于 2020-02-26 18:23:05
问题 I have celery beat and celery (four workers) to do some processing steps in bulk. One of those tasks is roughly along the lines of, "for each X that hasn't had a Y created, create a Y." The task is run periodically at a semi-rapid rate (10sec). The task completes very quickly. There are other tasks going on as well. I've run into the issue multiple times in which the beat tasks apparently become backlogged, and so the same task (from different beat times) are executed simultaneously, causing