user1629366
user1629366

Reputation: 2011

adding clocking support to heroku with python django

This article teaches how to run background jobs in heroku.

I have my clock.py file, in the same directory where Procfile is.

Following is my clock.py file:

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

I have updated my Procfile, to look as follows:

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

Earlier it used to look like:

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

Having done all this, I do the following in my terminal:

heroku ps:scale clock=1

And I get the following error:

Scaling clock processes... failed ! No such type as clock.

I have updated my requirements file, as mentioned in the article.

and here is the 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

What is wrong?

Upvotes: 1

Views: 768

Answers (1)

Kenneth Reitz
Kenneth Reitz

Reputation: 8846

Each process type should be on it's own line, like so:

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

Hope that helps!

Upvotes: 1

Related Questions