1

本文介绍如何在 heroku 中运行后台作业。

我有我的clock.py文件,在同一个目录中Procfile

以下是我的clock.py 文件:

from apscheduler.scheduler import Scheduler
from subscription.views import send_subs_mail
sched = Scheduler()


@sched.cron_schedule(day_of_week='sat', hour=23)
def scheduled_job():
    print 'This job is run every saturday at 11pm.'
    send_subs_mail()

sched.start()

while True:
    pass

我已经更新了我的 Procfile,如下所示:

web: newrelic-admin run-program gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT -w 3 
clock: python clock.py

之前它看起来像:

web: newrelic-admin run-program gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT -w 3 

完成所有这些后,我在终端中执行以下操作:

heroku ps:scale clock=1

我收到以下错误:

缩放时钟进程...失败!没有时钟这样的类型。

如文章中所述,我已经更新了我的需求文件。

这是heroku logs

2013-05-22T15:52:08.200587+00:00 heroku[web.1]: Starting process with command `newrelic-admin run-program gunicorn hellodjango.wsgi -b 0.0.0.0:48070 -w 3 clock: python clock.py`
2013-05-22T15:52:09.081883+00:00 heroku[web.1]: Process exited with status 0
2013-05-22T15:52:10.691985+00:00 app[web.1]: gunicorn: error: No application module specified.
2013-05-22T15:52:10.683457+00:00 app[web.1]: Usage: gunicorn [OPTIONS] APP_MODULE
2013-05-22T15:52:10.691843+00:00 app[web.1]: 
2013-05-22T15:52:12.504514+00:00 heroku[web.1]: Process exited with status 2
2013-05-22T15:52:12.525765+00:00 heroku[web.1]: State changed from crashed to starting
2013-05-22T15:52:12.525765+00:00 heroku[web.1]: State changed from starting to crashed
2013-05-22T15:52:16.198417+00:00 heroku[web.1]: Starting process with command `newrelic-admin run-program gunicorn hellodjango.wsgi -b 0.0.0.0:55149 -w 3 clock: python clock.py`
2013-05-22T15:52:17.343513+00:00 app[web.1]: Usage: gunicorn [OPTIONS] APP_MODULE
2013-05-22T15:52:17.343513+00:00 app[web.1]: gunicorn: error: No application module specified.
2013-05-22T15:52:17.343513+00:00 app[web.1]: 
2013-05-22T15:52:18.557818+00:00 heroku[web.1]: State changed from starting to crashed
2013-05-22T15:52:18.542409+00:00 heroku[web.1]: Process exited with status 2

怎么了?

4

1 回答 1

1

每个进程类型都应该在它自己的行上,如下所示:

web: newrelic-admin run-program gunicorn hellodjango.wsgi -b 0.0.0.0:$PORT -w 3
clock: python clock.py

希望有帮助!

于 2013-05-22T16:10:24.483 回答