Cron jobs not running (in dev)

2019-02-17 15:02发布

I've specified a cron job (to test in development) but it doesn't seem to be running. How does one make sure the jobs will work in production?

cron.yaml:

cron:
- description: cron test gathering
  url: /test/cron
  schedule: every 2 minutes from 09:00 to 23:00

app.yaml:

application: cron_test
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: main.py

main.py:

url_map = [ ('/test/cron', test.CronHandler),
            ('/error', err.Err404Handler)]

application = webapp.WSGIApplication(url_map, debug=False)

def main():
    wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
    main()

FeedCron is defined as:

class CronHandler(webapp.RequestHandler):

    def get(self):      
        logging.info("NOTE: CronHandler get request");
        return None

I was expecting to see the line, "NOTE: CronHandler get request", in the app engine's logs. I'm using the GoogleAppEngineLauncher app (version: 1.5.3.1187) to start & stop the app.

4条回答
forever°为你锁心
2楼-- · 2019-02-17 15:29

Three years later things have improved.

First, the route to Cron Jobs is: http://localhost:8000/cron

The development server (still) doesn't automatically run your cron jobs. However, using the link above you can do two things:

  1. Click the "Run now" button, which actually triggers the URL (hurray!)
  2. See the schedule, which should assure you of when the jobs would be run in production
查看更多
小情绪 Triste *
3楼-- · 2019-02-17 15:33

I was looking for a way to simulate cron jobs on the local dev server. As a temporary solution, I am running locally a python script which access the cron url and trigger the schedule task.

import urllib2
import time
while True:
    print urllib2.urlopen("http://localhost:9080/cron/jobs/")
    time.sleep(60)

In my case the url is http://localhost:9080/cron/jobs/ and I run it every minute. Hope it can help.

查看更多
疯言疯语
4楼-- · 2019-02-17 15:35

D'Oh! Just saw the fine print in the SDK documentation:

When using the Python SDK, the dev_appserver has an admin interface that allows you to view cron jobs at /_ah/admin/cron.

The development server doesn't automatically run your cron jobs. You can use your local desktop's cron or scheduled tasks interface to trigger the URLs of your jobs with curl or a similar tool.

查看更多
5楼-- · 2019-02-17 15:38

Well, my UI & backend codebase were decoupled. So I whipped up some ajax code on the UI to regularly hit the backend cron endpoints. That simulated the cron jobs for me in the local dev environment.

查看更多
登录 后发表回答