Google Appengine端点的Cron工作

时间:2022-02-06 23:13:01

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.

但是在Endpoints的文档中提到我们无法为GAE端点添加cron作业。

From Document: You cannot call a Google Cloud Endpoint directly from a push task queue or a cron job. GAE Endpoint Source: https://cloud.google.com/appengine/docs/java/endpoints/

来自文档:您无法直接从推送任务队列或cron作业调用Google Cloud Endpoint。 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

2 个解决方案

#1


2  

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调用的servlet的URL,然后在您的cron配置中,您只需告诉cron调用受管理员保护的URL。

Bit of a faff but works.

有点faff但是有效。

#2


0  

Does your cron need to call one of your Endpoints method ? 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.

你的cron是否需要调用你的一个端点方法?如果是,则需要将方法的代码放在单独的任务(或单独的webapp2处理程序)中,然后可以通过cron和Endpoints方法调用它们。

#1


2  

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调用的servlet的URL,然后在您的cron配置中,您只需告诉cron调用受管理员保护的URL。

Bit of a faff but works.

有点faff但是有效。

#2


0  

Does your cron need to call one of your Endpoints method ? 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.

你的cron是否需要调用你的一个端点方法?如果是,则需要将方法的代码放在单独的任务(或单独的webapp2处理程序)中,然后可以通过cron和Endpoints方法调用它们。