Skip to content

Commit

Permalink
Added a cron sample
Browse files Browse the repository at this point in the history
  • Loading branch information
meteatamel committed Apr 1, 2016
1 parent d6b3614 commit 7bf1caf
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
11 changes: 11 additions & 0 deletions managed_vms/cron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# App Engine Cron Service sample for Google App Engine
This sample demonstrates how to deploy App Engine Cron Service to ping a servlet deployed in the app.

## Running locally
$ mvn jetty:run

## Deploying app
$ mvn gcloud:deploy

## Deploying cron job
$ gcloud preview app deploy cron.yaml
63 changes: 63 additions & 0 deletions managed_vms/cron/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.example.managedvms</groupId>
<artifactId>managed-vms-cron</artifactId>

<parent>
<artifactId>doc-samples</artifactId>
<groupId>com.google.cloud</groupId>
<version>1.0.0</version>
<relativePath>../..</relativePath>
</parent>

<!-- [START dependencies] -->
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- [END dependencies] -->

<build>
<!-- for hot reload of the web application -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>gcloud-maven-plugin</artifactId>
<version>2.0.9.101.v20160316</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.3</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</plugin>
</plugins>
</build>
</project>
7 changes: 7 additions & 0 deletions managed_vms/cron/src/main/appengine/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
runtime: java
vm: true

handlers:
- url: /.*
script: this field is required, but ignored
secure: always
4 changes: 4 additions & 0 deletions managed_vms/cron/src/main/appengine/cron.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cron:
- description: sample cron job
url: /cron
schedule: every 1 mins
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.managedvms.cron;

import java.io.IOException;
import java.io.PrintWriter;

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

// [START example]
@WebServlet(name = "cron", value = "/cron")
@SuppressWarnings("serial")
public class CronServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
out.println("Hello from cron!");
}
}
// [END example]

0 comments on commit 7bf1caf

Please sign in to comment.