celery

Avoid recursive save() when using celery to update Django model fields

倖福魔咒の 提交于 2019-12-03 16:38:47
问题 I'm overriding a model's save() method to call an asynchronous task with Celery. That task also saves the model, and so I end up with a recursive situation where the Celery task gets called repeatedly. Here's the code: Model's save method: def save(self, *args, **kwargs): super(Route, self).save(*args, **kwargs) from .tasks import get_elevation_data get_elevation_data.delay(self) get_elevation_data task: from celery.decorators import task @task() def get_elevation_data(route): ... route

celery-django can't find settings

╄→гoц情女王★ 提交于 2019-12-03 16:32:01
问题 I have a Django project that uses Celery for running asynchronous tasks. I'm doing my development on a Windows XP machine. Starting my Django server ( python manage.py runserver 80 ) works fine, but attempting to start the Celery Daemon ( python manage.py celeryd start ) fails with the following error: ImportError: Could not import settings 'src.settings' (Is it on sys.path? Does it have syntax errors?): No module named src.settings sys.path includes 'C:\development\SpaceCorps\src', so I'm

Celery的一些社区资源-English

☆樱花仙子☆ 提交于 2019-12-03 16:27:36
Community Links Tweet Celery Best Practices Author: Deni Bertovic | Content type: Article Understanding the new messaging frameworks with virtual backends [Kombu] Author: Supercoderz | Content type: Article Scheduling Tasks Using Celery and Django Author: Nick Lang | Content type: Article Open graph and timeline sharing using Django Facebook Author: Thierry Schellenbach | Content type: Article Installing Stanford’s Class2Go Large-Scale Open Teaching Environment Author: Dr. Chuck | Content type: Article Instax - Making Celery monitoring easier Author: Timothee Peignier | Content type: Library

Capture Heroku SIGTERM in Celery workers to shutdown worker gracefully

时光怂恿深爱的人放手 提交于 2019-12-03 16:27:30
问题 I've done a ton of research on this, and I'm surprised I haven't found a good answer to this yet anywhere. I'm running a large application on Heroku, and I have certain celery tasks that run for a very long time processing, and at the end of the task save a result. Every time I redeploy on Heroku, it sends SIGTERM (and eventually, SIGKILL) and kills my running worker. I'm trying to find a way for the worker instance to shut itself down gracefully and re-queue itself for processing later so

Celery 和 Redis 入门

我只是一个虾纸丫 提交于 2019-12-03 16:27:16
Celery 是一个广泛应用于网络应用程序的任务处理系统。 它可以在以下情况下使用: 在请求响应周期中做网络调用 。服务器应当立即响应任何网络请求。如果在请求响应周期内需要进行网络调用,则应在周期外完成调用。例如当用户在网站上注册时,需要发送激活邮件。发送邮件是一种网络调用,耗时2到3秒。用户应该无需等待这2到3秒。因此,发送激活邮件应当在请求响应周期外完成,celery 就能实现这一点。 将一个由几个独立部分组成的大任务分成多个小任务 。假设你想知道脸书用户的时间流。脸书提供不同的端点来获取不同的数据。譬如,一个端点用以获取用户时间流中的图片,一个端点获取用户时间流中的博文,一个端点得到用户的点赞信息等。如果你的函数需要和脸书的5个端点依此通信,每个网络调用平均耗时2秒,你将需要10秒完成一次函数执行。但是,你可以把这项工作分为5个独立的任务(你很快就会发现这很容易做到),并让 celery 来处理这些任务。Celery 可以并行地与这5个端点通信,在2秒之内就能得到所有端点的响应。 ####简单的 celery 例子 假设我们有一个函数,并传给它一个网址列表。该函数需要获取这些网址的响应。 #####没有使用 celery 创建文件 celery_blog.py : import requests import time def func(urls): start = time

django与celery实现异步队列任务

微笑、不失礼 提交于 2019-12-03 16:26:37
Django使用初步 Using Celery with Django Note Previous versions of Celery required a separate library to work with Django, but since 3.1 this is no longer the case. Django is supported out of the box now so this document only contains a basic way to integrate Celery and Django. You’ll use the same API as non-Django users so you’re recommended to read the First Steps with Celery tutorial first and come back to this tutorial. When you have a working example you can continue to the Next Steps guide. Note Celery 4.0 supports Django 1.8 and newer versions. Please use Celery 3.1 for versions older than

django使用celery学习记录

懵懂的女人 提交于 2019-12-03 16:26:25
一. celery组件 实现一个异步的任务队列,最简单来看需要以下几个部分:任务消息的队列,任务执行者,任务结果存储 消息中间件 消息中间件即用来提供消息队列功能的组件,celery本身不提供,但是支持很多的类型的中间人:RabbitMQ, Redis, Mongodb, Django ORM等引擎。 任务执行者 任务执行者即worker,由celery提供的任务执行单元,这里就可以分布式的放在系统的各个节点中。实现并发的特性。 任务结果存储 用来存储任务运行的结果的组件,默认是没有的,可以自定义引擎,支持SQLAlchemy,cache, mongodb, redis等 二. celery的python简单使用 使用的环境为python2.7, redis3.0.7,这里准备使用redis作为消息中间件和结果存储。 1. 先定义tasks.py from celery import Celery app = Celery('tasks', backend="redis://127.0.0.1:6379/1", broker='redis://127.0.0.1:6379/0') #app.conf.CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite' #app.conf.CELERY_RESULT_BACKEND =

djcelery入门:实现运行定时任务

百般思念 提交于 2019-12-03 16:26:13
基于Django与Celery实现异步对列任务 - Python - 伯乐在线 http://python.jobbole.com/81953/ 更新于2015-08-26 注:本文根据官方文档结合具体例子整理,供celery入门学习,更多内容请移步参考资料一节。最近更新于2014-10-19 1 什么是celery celery是一个异步任务队列/基于分布式消息传递的作业队列。Celery通过消息(message)进行通信,使用代理(broker)在客户端和工作执行者之间进行交互。当开始一个任务时,客户端发送消息到队列并由代理将其发往响应的工作执行者处。 2 Windows环境配置 在这里使用RabbitMQ作为消息代理(broker),Django数据库作为结果存储(ResultStore)。 2.1 安装ERLang 首先是到ERLang官网去下载ERlang可执行文件 地址: http://www.erlang.org/download.html 然后安装ERLang。 然后设置ERLang的环境变量。 在环境变量中加入 ERL_HOME = erlang安装目录 在path中添加 %ERL_HOME%\bin 2.2 安装rabbitmq 从 http://www.rabbitmq.com/releases/rabbitmq-server/v3.1.5/rabbitmq

异步任务神器 Celery 简明笔记

孤街醉人 提交于 2019-12-03 16:25:56
在程序的运行过程中,我们经常会碰到一些耗时耗资源的操作,为了避免它们阻塞主程序的运行,我们经常会采用多线程或异步任务。比如,在 Web 开发中,对新用户的注册,我们通常会给他发一封激活邮件,而发邮件是个 IO 阻塞式任务,如果直接把它放到应用当中,就需要等邮件发出去之后才能进行下一步操作,此时用户只能等待再等待。更好的方式是在业务逻辑中触发一个发邮件的异步任务,而主程序可以继续往下运行。 Celery 是一个强大的分布式任务队列,它可以让任务的执行完全脱离主程序,甚至可以被分配到其他主机上运行。我们通常使用它来实现异步任务(async task)和定时任务(crontab)。它的架构组成如下图: 可以看到,Celery 主要包含以下几个模块: 任务模块 Task包含异步任务和定时任务。其中,异步任务通常在业务逻辑中被触发并发往任务队列,而定时任务由 Celery Beat 进程周期性地将任务发往任务队列。 消息中间件 BrokerBroker,即为任务调度队列,接收任务生产者发来的消息(即任务),将任务存入队列。Celery 本身不提供队列服务,官方推荐使用 RabbitMQ 和 Redis 等。 任务执行单元 WorkerWorker 是执行任务的处理单元,它实时监控消息队列,获取队列中调度的任务,并执行它。 任务结果存储 BackendBackend 用于存储任务的执行结果

MongoEngine and dealing with “UserWarning: MongoClient opened before fork. Create MongoClient with connect=False, or create client after forking”

和自甴很熟 提交于 2019-12-03 16:08:27
I am using Celery and MongoEngine as part of my Django App with. I am getting this warning, when a celery @shared_task accesses the mongodb database via mongoengine model classes: UserWarning: MongoClient opened before fork. Create MongoClient with connect=False,or create client after forking. See PyMongo's documentation for details: http://api.mongodb.org/python/current/faq.html#using-pymongo-with-multiprocessing It clearly has something to do with multiprocessing and pyMongo that is that mongoengine is based on. My question is: What is the best strategy to avoid this issue with mongoengine?