我刚刚开始使用 Google App Engine,所以我仍在学习如何配置所有内容。我编写了一个名为 parsexml.py 的脚本,我希望每 10 分钟左右运行一次。该文件位于我的主目录中,与 main.py、app.yaml 等一起。据我了解,我需要创建一个新文件 cron.yaml,如下所示:
cron:
- description: scrape xml
url: /
schedule: every 10 minutes
我不确定需要在 url 字段中输入什么内容。我也不确定是否还需要什么。我是否需要更改我的 app.yaml 文件?在哪里指定 parsexml.py 文件的名称?
Brian,
您需要更新您的app.yaml
and cron.yaml
文件。在每一个中,您都需要指定脚本运行的路径。
app.yaml
:
handlers:
- url: /path/to/cron
script: parsexml.py
或者,如果您有一个捕获所有处理程序,则无需更改它。例如:
handlers:
- url: /.*
script: parsexml.py
cron.yaml
:
cron:
- description: scrape xml
url: /path/to/cron
schedule: every 10 minutes
正如在文档 https://developers.google.com/appengine/docs/python/tools/webapp/running, in parsexml.py
你需要指定一个处理程序/path/to/cron
并使用 WSGI 处理程序注册它(或者您可以使用 CGI):
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class ParseXMLHandler(webapp.RequestHandler):
def get(self):
# do something
application = webapp.WSGIApplication([('/path/to/cron', ParseXMLHandler)],
debug=True)
if __name__ == '__main__':
run_wsgi_app(application)
Note:如果您使用的是Python 2.7运行时,您将需要指定script: parsexml.application
where application
是用于处理请求的全局 WSGI 变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)