[英]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.WSGIApplication
内taskcron.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.app
内app.yaml
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.