朋友您好我需要您在django应用程序的定期任务中提供帮助。我正在尝试使用芹菜做周期性任务,但它没有正常工作。我有一个简单的任务,其中只有一个print语句。芹菜只是第一次工作,我也尝试过芹菜打败,但没有结果
我的" task.py"是
let search180Query = ("http://www.180.no/bransje/" + (company.name?.stringByReplacingOccurrencesOfString(" ", withString: "-"))! + "/1.htm" as NSString).stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
和" view.py"
from __future__ import absolute_import
from myapp.celery import app
from celery.schedules import crontab
from celery.task import periodic_task
from celery.registry import tasks
@periodic_task(run_every=(crontab(minute='*/1')), name="some_task")
def every_minute(a,b):
print("This is running after one minute",a+b)
return "task done"
tasks.register(every_minute)
我刚刚在早期的芹菜设置中添加了这个时间表。" setting.py"
from django.http import HttpResponse
from django.views.generic import View
from .tasks import *
from .models import *
from datetime import datetime, timedelta
class CeleryTest(View):
def get(self,request):
send_date = datetime.now() + timedelta(seconds=200)
task=every_minute.apply_async([5,6],etc=send_date)
while not task.ready():
print "calling............task is not ready"
return HttpResponse("hi get ur task")
感谢各位朋友的时间。
答案 0 :(得分:2)
像这样使用你的日程....
CELERYBEAT_SCHEDULE = {
'every_minute': {
'task': 'every_minute',
},
}
并为celery运行此命令
python manage.py celeryd -BE -l info
现在我的周期性任务正常运行。