diff --git a/managed_vms/cron/README.md b/managed_vms/cron/README.md new file mode 100644 index 00000000000..1c8ed9fe65b --- /dev/null +++ b/managed_vms/cron/README.md @@ -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 \ No newline at end of file diff --git a/managed_vms/cron/pom.xml b/managed_vms/cron/pom.xml new file mode 100644 index 00000000000..58f4d741a1b --- /dev/null +++ b/managed_vms/cron/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + war + 1.0-SNAPSHOT + com.example.managedvms + managed-vms-cron + + + doc-samples + com.google.cloud + 1.0.0 + ../.. + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + jar + provided + + + + + + + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes + + + com.google.appengine + gcloud-maven-plugin + 2.0.9.101.v20160316 + + + org.apache.maven.plugins + maven-war-plugin + 2.6 + + false + + + + org.apache.maven.plugins + 3.3 + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.eclipse.jetty + jetty-maven-plugin + 9.3.7.v20160115 + + + + diff --git a/managed_vms/cron/src/main/appengine/app.yaml b/managed_vms/cron/src/main/appengine/app.yaml new file mode 100644 index 00000000000..2a659160df5 --- /dev/null +++ b/managed_vms/cron/src/main/appengine/app.yaml @@ -0,0 +1,7 @@ +runtime: java +vm: true + +handlers: +- url: /.* + script: this field is required, but ignored + secure: always diff --git a/managed_vms/cron/src/main/appengine/cron.yaml b/managed_vms/cron/src/main/appengine/cron.yaml new file mode 100644 index 00000000000..989f1fe8b3f --- /dev/null +++ b/managed_vms/cron/src/main/appengine/cron.yaml @@ -0,0 +1,4 @@ +cron: + - description: sample cron job + url: /cron + schedule: every 1 mins \ No newline at end of file diff --git a/managed_vms/cron/src/main/java/com/example/managedvms/cron/CronServlet.java b/managed_vms/cron/src/main/java/com/example/managedvms/cron/CronServlet.java new file mode 100644 index 00000000000..770ca75b468 --- /dev/null +++ b/managed_vms/cron/src/main/java/com/example/managedvms/cron/CronServlet.java @@ -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]