简体   繁体   English

Google Appengine端点的Cron工作

[英]Cron job for Google Appengine Endpoints

I like to add cron job for Google Appengine Endpoints. 我想为Google Appengine端点添加cron作业。

But in the document for the Endpoints mentioned that we cant add cron job for the GAE Endpoint. 但是在端点文档中提到,我们无法为GAE端点添加cron作业。

From Document: You cannot call a Google Cloud Endpoint directly from a push task queue or a cron job. 来自文档:您不能直接从推送任务队列或cron作业中调用Google Cloud Endpoint。 GAE Endpoint Source: https://cloud.google.com/appengine/docs/java/endpoints/ GAE端点来源: https//cloud.google.com/appengine/docs/java/endpoints/

Is there a way to add cron job for the endpoint? 有没有一种方法可以为端点添加cron作业?

Cron Source: https://cloud.google.com/appengine/docs/java/config/cron Cron来源: https : //cloud.google.com/appengine/docs/java/config/cron

You'll need to split the logic from your endpoint method out into a separate function or class. 您需要将逻辑从端点方法拆分为单独的函数或类。

You can then call that separate function/class from both a standard servlet AND the endpoints handler - this way both the servlet and the endpoint call the exact same code. 然后,您可以从标准servlet和端点处理程序中调用该单独的函数/类-这样,servlet和端点都调用完全相同的代码。

Then, in your web.xml you'll need to make sure that the URL for the servlet that will be called by cron is only accessible to admin users, then in your cron config you just tell cron to call the admin-protected URL. 然后,在web.xml中,需要确保只有cron用户才能访问cron调用的servlet的URL,然后在cron配置中,仅告诉cron调用受管理员保护的URL。

Bit of a faff but works. 有点麻烦但是有效。

Does your cron need to call one of your Endpoints method ? 您的cron是否需要调用您的Endpoints方法之一? If yes, you need to put the method's code in a separate task (or a separate webapp2 handler), which can then be called by both the cron and the Endpoints method. 如果是,则需要将方法的代码放在单独的任务(或单独的webapp2处理程序)中,然后可由cron和Endpoints方法调用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM