From 4d2cd563b5472d8cda01f9c98b038f46cd026a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20H=C3=A4berling?= Date: Fri, 29 Jun 2018 19:32:03 -0700 Subject: [PATCH] Add a ping-cronjob to keep instance alive. Use a cron-job to prevent the AppEngine instance from going to sleep. This should keep requests quick since the JVM is not being restarted often on new requests and all caches stay intact. This addresses issue #1. --- .../main/java/org/retrostore/MainServlet.java | 2 ++ .../org/retrostore/request/PingRequest.java | 36 +++++++++++++++++++ appengine/src/main/webapp/WEB-INF/cron.xml | 24 +++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 appengine/src/main/java/org/retrostore/request/PingRequest.java create mode 100644 appengine/src/main/webapp/WEB-INF/cron.xml diff --git a/appengine/src/main/java/org/retrostore/MainServlet.java b/appengine/src/main/java/org/retrostore/MainServlet.java index 3974d0a..6926687 100644 --- a/appengine/src/main/java/org/retrostore/MainServlet.java +++ b/appengine/src/main/java/org/retrostore/MainServlet.java @@ -43,6 +43,7 @@ import org.retrostore.request.FaviconRequest; import org.retrostore.request.ImportRpkRequest; import org.retrostore.request.LoginRequest; +import org.retrostore.request.PingRequest; import org.retrostore.request.PolymerRequest; import org.retrostore.request.PublicSiteRequest; import org.retrostore.request.ReportAppRequest; @@ -114,6 +115,7 @@ static class Modules { private static List createRequests(Modules m) { return ImmutableList.of(new FaviconRequest(m.defaultResourceLoader), + new PingRequest(), new PublicSiteRequest(m.defaultResourceLoader), new ReportAppRequest(m.defaultResourceLoader, m.appManagement, m.imgServWrapper, m.mailService), diff --git a/appengine/src/main/java/org/retrostore/request/PingRequest.java b/appengine/src/main/java/org/retrostore/request/PingRequest.java new file mode 100644 index 0000000..c2c72be --- /dev/null +++ b/appengine/src/main/java/org/retrostore/request/PingRequest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2018, Sascha Häberling + * + * 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 org.retrostore.request; + +import org.retrostore.data.user.UserService; + +/** + * We use ping requests to check that the AppEngine instance is alive. This is the class that + * handles these requests. + */ +public class PingRequest implements Request { + private static final String PATH_SERVE = "/ping"; + + @Override + public boolean serveUrl(RequestData requestData, Responder responder, UserService userService) { + if (!PATH_SERVE.equals(requestData.getUrl())) { + return false; + } + responder.respond("OK", Responder.ContentType.PLAIN); + return true; + } +} diff --git a/appengine/src/main/webapp/WEB-INF/cron.xml b/appengine/src/main/webapp/WEB-INF/cron.xml new file mode 100644 index 0000000..b1eabd6 --- /dev/null +++ b/appengine/src/main/webapp/WEB-INF/cron.xml @@ -0,0 +1,24 @@ + + + + + + /ping + Keep-alive for the AppEngine instance. + every 1 minutes + + \ No newline at end of file