【问题标题】:How can i make my new periodictask working Django 1.6 /Python我怎样才能让我的新周期任务工作 Django 1.6 /Python
【发布时间】:2016-09-28 10:59:15
【问题描述】:

我有一个 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.'

我配置了 celery 设置:

[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'},
}

我无法完成这项任务,请帮助! 谢谢!

【问题讨论】:

    标签: django python-2.7 celery


    【解决方案1】:

    您可以尝试使用 Django 管理命令,

    与运行 runserver、shell 和 dbshel​​l 等的方式相同。

    http://django-chinese-docs-16.readthedocs.io/en/latest/howto/custom-management-commands.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 2011-04-26
      • 1970-01-01
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多