Skip to content

Commit

Permalink
Add a ping-cronjob to keep instance alive.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shaeberling committed Jun 30, 2018
1 parent 8fda430 commit 4d2cd56
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions appengine/src/main/java/org/retrostore/MainServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -114,6 +115,7 @@ static class Modules {

private static List<Request> 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),
Expand Down
36 changes: 36 additions & 0 deletions appengine/src/main/java/org/retrostore/request/PingRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
24 changes: 24 additions & 0 deletions appengine/src/main/webapp/WEB-INF/cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->

<cronentries>
<cron>
<url>/ping</url>
<description>Keep-alive for the AppEngine instance.</description>
<schedule>every 1 minutes</schedule>
</cron>
</cronentries>

0 comments on commit 4d2cd56

Please sign in to comment.