编程语言
首页 > 编程语言> > java – 如何在Web界面的“计划任务”选项卡中显示应用程序引擎cron作业?

java – 如何在Web界面的“计划任务”选项卡中显示应用程序引擎cron作业?

作者:互联网

我一直在构建一个应用程序,将谷歌分析数据从Bigquery的数据集转移到谷歌存储.

我的目的是在Google App Engine上部署一个Web应用程序,并设置一些cron作业来定期调用正确的URL,然后让一些servlet来管理这些请求.

我正在开发eclipse并使用Google提供的App Engine插件https://developers.google.com/eclipse/.

使用这个插件,我创建了一个“基于Maven的Google App Engine标准Java项目”,其中包含一个简单的java servlet HelloAppEngine.java,一个基本的index.jsp页面和一个带有简单方法的类.这是这三个的代码,web.xml和appengine-web.xml.

HelloAppEngine.java:

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloAppEngine extends HttpServlet {

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws IOException {

    response.setContentType("text/plain");
    response.getWriter().println("Hello App Engine!");

  }
}

的index.jsp:

<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="bigqueryexport.HelloInfo" %>
<html>
<head>
  <link href='//fonts.googleapis.com/css?family=Marmelad' rel='stylesheet' type='text/css'>
  <title>Hello App Engine Standard</title>
</head>
<body>
    <h1>Hello App Engine -- Standard!</h1>

  <p>This is <%= HelloInfo.getInfo() %>.</p>
  <table>
    <tr>
      <td colspan="2" style="font-weight:bold;">Available Servlets:</td>
    </tr>
    <tr>
      <td><a href='/hello'>The servlet</a></td>
    </tr>
  </table>

</body>
</html>

这是web.xml:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
  <servlet>
    <servlet-name>HelloAppEngine</servlet-name>
    <servlet-class>bigqueryexport.HelloAppEngine</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloAppEngine</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

最后,appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <threadsafe>true</threadsafe>
    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    </system-properties>
</appengine-web-app>

到目前为止,我已经编写了一行代码,当我将此代码部署到Google平台时,一切正常.现在,根据https://cloud.google.com/appengine/docs/standard/java/config/cron,只需添加一个带有正确代码的cron.xml文件并再次部署应用程序,就应该准备好了.这是我在appengine-web.xml所在的同一文件夹中创建的cron.xml.

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
  <cron>
    <url>/hello</url>
    <description>test cron job</description>
    <schedule>every 3 minutes</schedule>
  </cron>
</cronentries>

根据上面提供的文档,这应该创建一个计划任务,每3分钟向我的servlet发出一次get请求,但是当我再次部署应用程序时,cron作业将不会显示在google平台界面上,它赢了每3分钟工作一次.

我在这里错过了什么?

谢谢

PS:这是控制台上的编译输出.

Beginning interaction for module default… 0% Scanning for jsp files.
0% Compiling jsp files. abr 04, 2017 4:34:24 PM org.apache.jasper.JspC
processFile INFORMACI�N: Built File: \index.jsp warning: [options]
bootstrap class path not set in conjunction with -source 1.7 Success.
Temporary staging for module default directory left in
D:\somepath
You are about to deploy the following services:
– project-id/default/20170404t163438 (from [D:\somepath\app.yaml])
Deploying to URL: [07002

Beginning deployment of service [default]… File upload done.
Updating service [default]… ………………………..done.
Deployed service [default] to [07002

You can stream logs from the command line by running: $gcloud app
logs tail -s default

To view your application in the web browser run: $gcloud app browse

解决方法:

仅供参考,您可以在{buildOutputPath} / appengine-staged / WEB-INF / appengine-generated /目录中找到cron.yaml文件.

gcloud app deploy –project = yourprojectname cron.yaml会将cron作业部署到您的项目中.

标签:java,google-bigquery,google-app-engine,cron,servlets
来源: https://codeday.me/bug/20190823/1700772.html