Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Backends using Cron in Google App Engine (Java)

I have a Dynamic Backend setup on GAE which I want to run using cron every 15mins. The problem is cron requires a url that begins with "/". While a backend URL uses the following format: http://backendname.yourapp.appspot.com.

I've read in other forums that you could use fetchurl to call your backend but I don't think that's the ideal way. Because that would require you to make your backend publicly accessible.

According to google's documentation: http://code.google.com/appengine/docs/java/backends/overview.html#Public_and_Private_Backends

"Private backends can be accessed by application administrators, instances of the application, and by App Engine APIs and services (such as Task Queue tasks and Cron jobs) without any special configuration."

Has anybody got backends called by declaring it in cron.xml?

like image 353
Jay Q. Avatar asked Jul 11 '11 17:07

Jay Q.


People also ask

How do I schedule a cron job in Java?

Java Cron ExpressionThe @EnableScheduling annotation is used to enable the scheduler for your application. This annotation should be added into the main Spring Boot application class file. The @Scheduled annotation is used to trigger the scheduler for a specific time period.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week . 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.


2 Answers

Use target tag to specify a backend in your cron.xml.

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
  <cron>
    <url>/long-task</url>
    <description></description>
    <schedule>every 30 minutes</schedule>
    <target>name-of-the-backend</target>
  </cron>
</cronentries>
like image 134
lyxera Avatar answered Nov 16 '22 04:11

lyxera


urlfetch can be used to access internal-only URLs such as private backends - if that weren't possible, there'd be no way to communicate within your app! A better idea, though, might be to use the Task Queue, which can be configured to run tasks against a backend.

like image 42
Nick Johnson Avatar answered Nov 16 '22 02:11

Nick Johnson