应用引擎定时任务在生产环境中未运行

0 投票
1 回答
1339 浏览
提问于 2025-04-16 13:07

我刚把我的应用上传到应用引擎,其他功能都正常,但定时任务(cron jobs)却没有运行。我在根目录下有一个cron.yaml文件,内容大致是这样的:

cron:
- description: do stuff
  url: /cron/dostuff
  schedule: every 1 minutes

- description: do other stuff
  url: /cron/dootherstuff
  schedule: every 1 days

这个文件对应我app.yaml文件中的一部分:

- url: /cron
  script: main.py
  login: admin

而这个又对应到我main.py文件中的应用部分,内容是:

# cron
('/cron/(.*)',handlers.CronHandler),

最后,这一切又连接到CronHandler程序,像这样:

class CronHandler(BaseHandler):
    def get(self, mode=""):
        if mode == "dostuff":
            # stuff should happen here

我已经把应用上传到谷歌,其他功能都正常。当我直接访问定时任务的URL(比如说myapp.appspot.com/cron/dostuff)时,它也能正常工作。但定时任务却没有自动运行,当我进入控制面板查看定时任务页面时,看到的是这个。

enter image description here

你觉得我哪里做错了吗?

1 个回答

3

我搞明白了。单独使用“days”而不指定具体时间,是不合法的调度方式。我需要把它改成“每24小时”或者“每天00:00”。如果cron.yaml的文档能更清楚地说明这些选项就好了。

撰写回答