Skip to content

Commit f5c436e

Browse files
committed
Merge pull request #143 from meteatamel/master
Added a cron sample
2 parents d6b3614 + 7bf1caf commit f5c436e

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

managed_vms/cron/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# App Engine Cron Service sample for Google App Engine
2+
This sample demonstrates how to deploy App Engine Cron Service to ping a servlet deployed in the app.
3+
4+
## Running locally
5+
$ mvn jetty:run
6+
7+
## Deploying app
8+
$ mvn gcloud:deploy
9+
10+
## Deploying cron job
11+
$ gcloud preview app deploy cron.yaml

managed_vms/cron/pom.xml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
<packaging>war</packaging>
7+
<version>1.0-SNAPSHOT</version>
8+
<groupId>com.example.managedvms</groupId>
9+
<artifactId>managed-vms-cron</artifactId>
10+
11+
<parent>
12+
<artifactId>doc-samples</artifactId>
13+
<groupId>com.google.cloud</groupId>
14+
<version>1.0.0</version>
15+
<relativePath>../..</relativePath>
16+
</parent>
17+
18+
<!-- [START dependencies] -->
19+
<dependencies>
20+
<dependency>
21+
<groupId>javax.servlet</groupId>
22+
<artifactId>javax.servlet-api</artifactId>
23+
<version>3.1.0</version>
24+
<type>jar</type>
25+
<scope>provided</scope>
26+
</dependency>
27+
</dependencies>
28+
<!-- [END dependencies] -->
29+
30+
<build>
31+
<!-- for hot reload of the web application -->
32+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
33+
<plugins>
34+
<plugin>
35+
<groupId>com.google.appengine</groupId>
36+
<artifactId>gcloud-maven-plugin</artifactId>
37+
<version>2.0.9.101.v20160316</version>
38+
</plugin>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-war-plugin</artifactId>
42+
<version>2.6</version>
43+
<configuration>
44+
<failOnMissingWebXml>false</failOnMissingWebXml>
45+
</configuration>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<version>3.3</version>
50+
<artifactId>maven-compiler-plugin</artifactId>
51+
<configuration>
52+
<source>1.8</source>
53+
<target>1.8</target>
54+
</configuration>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.eclipse.jetty</groupId>
58+
<artifactId>jetty-maven-plugin</artifactId>
59+
<version>9.3.7.v20160115</version>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
runtime: java
2+
vm: true
3+
4+
handlers:
5+
- url: /.*
6+
script: this field is required, but ignored
7+
secure: always
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cron:
2+
- description: sample cron job
3+
url: /cron
4+
schedule: every 1 mins
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.managedvms.cron;
18+
19+
import java.io.IOException;
20+
import java.io.PrintWriter;
21+
22+
import javax.servlet.annotation.WebServlet;
23+
import javax.servlet.http.HttpServlet;
24+
import javax.servlet.http.HttpServletRequest;
25+
import javax.servlet.http.HttpServletResponse;
26+
27+
// [START example]
28+
@WebServlet(name = "cron", value = "/cron")
29+
@SuppressWarnings("serial")
30+
public class CronServlet extends HttpServlet {
31+
32+
@Override
33+
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
34+
PrintWriter out = resp.getWriter();
35+
out.println("Hello from cron!");
36+
}
37+
}
38+
// [END example]

0 commit comments

Comments
 (0)