【问题标题】:GAE Python - Cron job doesn't execute on the target moduleGAE Python - Cron 作业不在目标模块上执行
【发布时间】:2014-01-17 11:49:07
【问题描述】:

我刚刚在 GAE 上实现了模块,并试图从某个模块运行 Cron 作业。我的 app.yaml 在顶部有以下值:

application: myapp
module: default
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
#all handlers

我尝试激活的模块的reporting.yaml 具有以下设置:

application: myapp
module: reporting
version: 1
instance_class: B4
runtime: python27
api_version: 1
threadsafe: true

handlers:
#same handlers as app.yaml

最后我的 cron.yaml 如下所示:

cron:
- description: update reports
  url: /update
  schedule: every day 12:00
  target: reporting

我需要该模块,因为该作业需要比普通实例提供的更多内存。然而,出于某种原因,当我查看我的应用程序的日志时,它会继续在默认模块上执行 cron 作业。为什么不接受目标参数?

【问题讨论】:

    标签: python google-app-engine module cron gae-module


    【解决方案1】:

    原来我错过了使用以下命令上传模块本身:

    appcfg update app.yaml reporting.yaml
    

    执行此操作后,目标参数起作用了。

    【讨论】:

    • 您能告诉我如何为您的 cron 作业正确设置处理程序吗?我有一个类似的问题,我正在尝试加载另一个需要更多内存的模块......只是不确定如何设置处理程序以便将 *.py 脚本作为 cron 作业运行。因此,例如,我有 abc.py,我想将它作为一个 cron 作业运行,它是 module.yaml 的一部分。提前谢谢你
    • 我不使用 distpatch.yaml,所以我猜你不必更新它。在这种情况下,我的处理程序将是第一行“- url:/update”,然后是第二行“script:update.app”,它将从 update.py 调用应用程序
    • 感谢您的回复——您能看看this,看看您是否发现有问题?我觉得我做的一切都是正确的,但是当我尝试运行 cron 作业时出现 404 错误..
    • 好的,修好了——我需要专门用 appcfg.py update_cron 更新 cron.yaml
    • 太棒了。如果您有任何问题,请告诉我。
    【解决方案2】:

    请检查来自GAE document 的以下文本 - 版本不是模块的目标元素。

    如果已为作业设置了目标参数,则将请求发送到 指定的版本

    像下面GAE document 中的示例代码一样,将 cron 作业转发到您的目标模块怎么样?

    import urllib2
    from google.appengine.api import modules
    
    url = "http://%s/" % modules.get_hostname(module="reporting")
    try:
      result = urllib2.urlopen(url)
      doSomethingWithResult(result)
    except urllib2.URLError, e:
      handleError(e)
    

    【讨论】:

    • 感谢您的意见,Wonil。原来我只需要正确更新模块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 2013-05-27
    • 1970-01-01
    • 2013-10-04
    相关资源
    最近更新 更多