简体   繁体   English

在 Google App Engine (Java) 中使用 Cron 执行后端

[英]Execute Backends using Cron in Google App Engine (Java)

I have a Dynamic Backend setup on GAE which I want to run using cron every 15mins.我在 GAE 上有一个动态后端设置,我想每 15 分钟使用 cron 运行一次。 The problem is cron requires a url that begins with "/".问题是 cron 需要一个以“/”开头的 url。 While a backend URL uses the following format: http://backendname.yourapp.appspot.com .而后端 URL 使用以下格式: http://backendname.yourapp.appspot.com

I've read in other forums that you could use fetchurl to call your backend but I don't think that's the ideal way.我在其他论坛上读到您可以使用 fetchurl 来调用您的后端,但我认为这不是理想的方式。 Because that would require you to make your backend publicly accessible.因为这需要你让你的后端公开访问。

According to google's documentation: http://code.google.com/appengine/docs/java/backends/overview.html#Public_and_Private_Backends根据谷歌的文档: http://code.google.com/appengine/docs/java/backends/overview.html#Public_and_Private_Backends

"Private backends can be accessed by application administrators, instances of the application, and by App Engine APIs and services (such as Task Queue tasks and Cron jobs) without any special configuration." “应用程序管理员、应用程序实例以及 App Engine API 和服务(例如任务队列任务和 Cron 作业)无需任何特殊配置即可访问私有后端。”

Has anybody got backends called by declaring it in cron.xml?有没有人通过在 cron.xml 中声明来调用后端?

Use target tag to specify a backend in your cron.xml.使用目标标签在您的 cron.xml 中指定一个后端。

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
  <cron>
    <url>/long-task</url>
    <description></description>
    <schedule>every 30 minutes</schedule>
    <target>name-of-the-backend</target>
  </cron>
</cronentries>

urlfetch can be used to access internal-only URLs such as private backends - if that weren't possible, there'd be no way to communicate within your app, A better idea, though, might be to use the Task Queue. urlfetch 可用于访问仅限内部的 URL,例如私有后端 - 如果不可能,则无法在您的应用程序内进行通信,但更好的主意可能是使用任务队列。 which can be configured to run tasks against a backend.可以配置为针对后端运行任务。

I haven't try google app engine's Backends functions, because its pricing model.我没有尝试谷歌应用引擎的后端功能,因为它的定价 model。 However, according to the documents:但是,根据文件:

http://code.google.com/appengine/docs/python/backends/overview.html#Public_and_Private_Backends http://code.google.com/appengine/docs/python/backends/overview.html#Public_and_Private_Backends

Backends are private by default, since they typically function as a component inside an application, rather than acting as its public face.默认情况下,后端是私有的,因为它们通常 function 作为应用程序内部的组件,而不是作为其公共面孔。

I think GAE will automatically hide the backend url from public http visiting (even without the needs to configure the app.yaml).我认为 GAE 会自动隐藏后端 url 以防止公共 http 访问(即使不需要配置 app.yaml)。 You may test its behavior by logout and access the backend url directly.您可以通过注销并直接访问后端 url 来测试其行为。

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

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