简体   繁体   English

Google应用程序引擎python cron:app.yaml文件中的testcron.py在做什么?

[英]Google app engine python cron: What is the testcron.py doing in the app.yaml file?

Here's a sample code for gae python cron job. 这是gae python cron作业的示例代码。

app.yaml app.yaml

- url: /testcron
  script: testcron.py
  login: admin

- url: .*
  script: main.app

cron.yaml cron.yaml

cron:
- description: testcron
  url: /testcron
  schedule: every 12 hours

main.py main.py

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.request.write('hello')

class TestCronHandler(webapp2.RequestHandler):
    def get(self):
        logging.info('hello')


app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/testcron',TestCronHandler)
], debug=True)

Okay, so I've noticed that you do not need script: testcron.py in the app.yaml file. 好的,所以我注意到您不需要script: testcron.py app.yaml文件中的script: testcron.py But if you put it there, it is required to run another application. 但是,如果将其放在此处,则需要运行另一个应用程序。

So what is the purpose of that? 那目的是什么? I mean you can run it in TestCronHandler. 我的意思是您可以在TestCronHandler中运行它。 What is the difference between running in main.app handler and running in testcron.py? 在main.app处理程序中运行与在testcron.py中运行之间有什么区别? (It seems like you need to run another app with testcron.py) (似乎您需要使用testcron.py运行另一个应用程序)

It's not really clear what you mean by 你的意思不是很清楚

if you put it there, it is required to run another application 如果放在那里,则需要运行另一个应用程序

and

It seems like you need to run another app with testcron.py 似乎您需要使用testcron.py运行另一个应用程序

If you mean you need to define another app = webapp2.WSGIApplication inside taskcron.py then yes, that is true but it looks like you don't have the testcron.py file at all and your main.py is handling requests to /testcron so your app.yaml could look as simple as: 如果你的意思是你需要定义的另一个app = webapp2.WSGIApplicationtaskcron.py然后是的,这是事实,但它看起来像你没有testcron.py在所有的文件和你的main.py正在处理的请求/testcron因此您的app.yaml看起来可能很简单:

- url: .*
  script: main.app

It's up to you whether you want to separate (for better code organization?) cron requests/handlers into a separate file but note that if you have a file called taskcron. 是否要(为了更好的代码组织?)将cron请求/处理程序分离到一个单独的文件中,取决于您,但是请注意,如果您有一个名为taskcron的文件。 py it would need to appear in app.yaml as "script: taskcron. app ". PY那就需要在出现app.yaml为“脚本:taskcron 应用 ”。

Also, an important security note, if you want to make sure that regular users cannot access your cron task URLs then you should definitely move your cron task handlers into a separate file and keep the login: admin line below script: testcron.app inside app.yaml . 此外,一个重要的安全注意事项,如果你想确保普通用户无法访问您的cron任务网址,那么你一定要你的cron任务的处理程序移动到一个单独的文件,并保持login: admin下面一行script: testcron.appapp.yaml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 app.yaml文件:运行2个Python文件Google App Engine - app.yaml file: Running 2 Python Files Google App Engine Google App Engine | Python |的app.yaml - Google App Engine | Python | APP.YAML 如何使用Google App Engine Python将变量从app.yaml传递到main.py. - How to pass a variable from app.yaml to main.py with Google App Engine Python 如何为Google App Engine应用程序写入`app.yaml`文件? - How to write `app.yaml` file for Google App Engine app? main.py或app.yaml是否确定此示例中App Engine cron任务使用的URL? - Does main.py or app.yaml determine the URL used by the App Engine cron task in this example? 要在Google App Engine上托管静态(HTML)网站,app.yaml文件中应包含哪些内容? - To host a static (HTML) website on Google App Engine, what should be in the app.yaml file? app.yaml /项目文件结构适用于app引擎localhost调试器,但不适用于谷歌应用引擎服务器 - app.yaml / project file structure works on app engine localhost debugger but not on google app engine server 问:谷歌应用引擎app.yaml如何处理main.py中的网址? - Q: google app engine app.yaml how to handle urls from within main.py? Google App Engine:运行dev_appserver.py app.yaml,但没有任何反应 - Google App Engine: run dev_appserver.py app.yaml but nothing happens Python App Engine:使用app.yaml来控制url处理程序 - Python App Engine : use app.yaml to control url handler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM