在我的模型中,我有一个默认值为“status”的字段。在Django管理界面中,用户单击“Save”按钮后,表单输入将传递给一个只休眠30秒的芹菜任务。
在那30秒之后,我如何:
确定芹菜任务是否成功?
将模型的status字段从“处理”更新到实际状态(例如:已完成,失败?
models.py
from django.db import models
class Scorecard(models.Model):
name = models.CharField(max_length=100, unique=True)
status = models.CharF
我在我的项目中有这样的布局:(因为文档必须是这样的)
/zonia
/backend
__init__.py
celery.py
...
/musics
tasks.py
...
...
在init.py中:
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will us
所以我一直在努力弄清楚如何安排任务,我找到了芹菜,并且能够做简单的预定任务。要做到这一点,我需要打开一个命令行并运行celery -A proj beat来完成任务。这在开发环境中很好,但是当将它投入生产时,这将是一个问题。
那么,如果没有命令行的使用,我如何才能让芹菜工作呢?当我的生产服务器在线时,如何确保我的调度器与它一起运行?芹菜能做到这一点吗?还是我需要另一种方法?
我有一个简单的函数,可以遍历PostgresSQL列表,使用GET检索一些信息并相应地更新DB (URL)。这个函数运行得很完美。然而,一次浏览一个URL会花费太多的时间。
使用python,我能够执行以下操作来并行执行这些任务:
from multiprocessing import Pool
def updateDB(ip):
code goes here...
if __name__ == '__main__':
pool = Pool(processes=4) # process per core
pool.map
我试图使用芹菜定期查询外部api,并使用新数据更新Django项目中的数据库。芹菜正确地安排任务并发送给芹菜工人,但是它从不执行任何事情。
下面是我的celery.py文件,它与我的settings.py处于相同的级别:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from django.conf import settings
from celery.schedules import crontab
os.environ.setdefault(
我有一个运行良好的Django 2.0项目,它与Celery 4.1.0集成,我使用jquery将ajax请求发送到后端,但由于芹菜的一些问题,我只是无休止地实现了它的加载。
芹菜设置(celery.py)
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('
我们有一个带有芹菜的Django应用程序来处理异步任务。我们使用AWS SQS作为任务代理。
我们最终得到了一个要处理的糟糕任务(删除了任务实现而没有删除芹菜节拍条目)。这导致了以下错误:
Received unregistered task of type KeyError('some_deleted_task').
The message has been ignored and discarded.
一旦我们清理了芹菜节拍条目,我们就继续得到错误~2分钟( SQS上的能见度超时设置为2分钟)。
行为似乎是:
任务添加到队列中,在SQS中作为“可用”
工作人员拿起任