Google Cloud App Engine Cron作业-不调用服务 [英] Google Cloud App Engine cron job - not calling the service

查看:137
本文介绍了Google Cloud App Engine Cron作业-不调用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功使用App Engine标准环境为Java应用程序将Cron作业部署到App Engine。它成功部署,但是cron作业失败,并且当我检查日志时,它没有调用正确的服务:

I've successfully deployed a Cron job to App Engine, for a Java application using the App Engine Standard environment. It deploys successfully, however the cron job fails, and when I check the log, it isn't calling the correct service:

"GET /my-app HTTP/1.1" 404 - - "AppEngine-Google; (+http://code.google.com/appengine)"
"my-project.appspot.com"

其他正在执行的cron作业如下所示(请注意,最后一部分显示了服务名称,而不仅仅是项目名称):

Other cron jobs that are working look like this (note that the last part shows the service name and not just the project name):

"GET /my-app HTTP/1.1" 404 - - "AppEngine-Google; (+http://code.google.com/appengine)"
"my-service.my-project.appspot.com"

这是我的 cron.xml

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
    <cron>
        <url>/my-app</url>
        <description>my app</description>
        <schedule>every 1 minutes from 00:00 to 23:00</schedule>
        <timezone>Europe/Paris</timezone>
    </cron>
</cronentries>

和我的 web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <servlet>
      <servlet-name>my-app</servlet-name>
      <servlet-class>com.my.package.MyApp</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>my-app</servlet-name>
      <url-pattern>my-app</url-pattern>
  </servlet-mapping>


</web-app>

还有我的servlet定义(这是一个Cloud Endpoint应用程序,它使用Java servlet):

And my servlet definition (this is a Cloud Endpoint app, which uses a Java servlet):

@WebServlet(
        name = "my-app",
        urlPatterns = {"/my-app"}
)
public class MyApp extends HttpServlet {
   ...

还有我的 appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  ....    

  <application>my-project</application>
  <service>my-app</service>

  ....

</appengine-web-app>

为什么cron作业不调用该服务?该服务也已正确部署。

Why isn't the cron job calling the service? The service is also correctly deployed.

推荐答案

从官方文档中

以下示例创建了一个运行的基本cron作业每天:

The following example creates a basic cron job that runs daily:

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
  <cron>
    <url>/tasks/summary</url>
    <target>beta</target>
    <description>daily summary job</description>
    <schedule>every 24 hours</schedule>
  </cron>
</cronentries>




目标规范是可选的,是$ b $的名称b服务/版本。目标(如果存在)位于应用程序的
主机名之前,从而将作业路由到该服务/版本。如果未指定
目标,则该作业将在为流量配置的默认
服务版本中运行。

The target specification is optional and is the name of a service/version. If present, the target is prepended to your app's hostname, causing the job to be routed to that service/version. If no target is specified, the job will run in the versions of the default service that are configured for traffic.

我认为这就是您的情况。由于未指定 target ,因此cron作业在默认服务上达到了/ my-app路由。在目标中提及服务名称。

I think this is what is happening in your case. Since you have not specified the target, the cron job is hitting the /my-app route on default service. Mention the service name in the target.

这篇关于Google Cloud App Engine Cron作业-不调用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆