我有一个Django项目需要维护, 我会添加新的周期性任务: 的 tasks.py
类ArchiveJobsTask(PeriodicTask):
run_every = crontab()
def run(self, **kwargs):
logger.info('Arching jobs')
qs = Job.objects.filter(status='W', expiration_date__lt= datetime.datetime.today().date()).update(status='A')
return 'Jobs archived.'
我配置了芹菜设置:
[program:celery]
; Set full path to celery program if using virtualenv
command=/var/www/keejob_env/bin/celery worker -A keejob --loglevel=INFO -Q jobs,experiences
directory=/var/www/keejob_env/keejob
user=www-data
numprocs=1
stdout_logfile=/var/log/celery/worker.log
stderr_logfile=/var/log/celery/worker.log
autostart=true
autorestart=true
startsecs=10
; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 166600
; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true
; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998
我的设置文件:setting.py:
CELERY_ROUTES = {
'mailing.tasks.SendJobAlerts': {'queue': 'alerts'},
'mailing.tasks.SendApplicationEmail': {'queue': 'applications'},
'job_applications.tasks.ApplicationNotifyResponsibleTask': {'queue': 'applications'},
'recruiter.jobs.tasks.SendDailyApplicationsTask': {'queue': 'jobs'},
'recruiter.jobs.tasks.SendDailyExpirationTask': {'queue': 'jobs'},
'recruiter.jobs.tasks.RefreshJobsTask': {'queue': 'jobs'},
'recruiter.jobs.tasks.ArchiveJobsTask': {'queue': 'jobs'},
'jobseeker.tasks.CronExperienceJobseekerTask': {'queue': 'experiences'},
}
我无法完成此任务,请帮助! 谢谢!
答案 0 :(得分:0)
您可以尝试使用Django管理命令
运行runserver,shell和dbshell等同样的方式。
http://django-chinese-docs-16.readthedocs.io/en/latest/howto/custom-management-commands.html