What is equivalent GAE cron expression for following - google-app-engine

I have spring cron equation.
I need equivalent GAE cron for those.
GAE cron doc seems bit complex.
cron="0 0 7 * * MON-FRI"
cron="0 30 9 * * "SUN"
I need equivalent GAE cron for those

You need to create a new file called cron.xml into WEB-INF folder. For example this cron runs the url indicated every 5 days, but you can also configure the schedule format.
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/url</url>
<description>Information about cron job</description>
<schedule>every 24 hours</schedule>
</cron>
</cronentries>
The complete reference is here:
https://cloud.google.com/appengine/docs/java/config/cron
Here examples about change schedule format:
https://cloud.google.com/appengine/docs/flexible/java/scheduling-jobs-with-cron-yaml

Related

App Engine cron jobs not running - Standard Environment - Java

As the title says, I have a number of cron jobs set up on my Java web application hosted on AppEngine standard environment, but one or two of them fail to run.
Examining the logs, I can see that the httpRequest for the ones that fail have 302 error code, indicating that the URL can't be found. The ones that work, return 200 as expected.
I can manually invoke the cron jobs' URLs and they work so it doesn't appear to really be a 302 problem. From the logs, Chrome sees a 200 response, but AppEngine sees 302:
The cron.xml file is in the correct place and works for the other jobs. this is the cron entry that's failing:
<cronentries>
<cron>
<url>/home/cron/boatactivity/</url>
<description>generate activities for boat movement</description>
<schedule>every 3 hours from 00:00 to 21:00</schedule>
</cron>
</cronentries>
And this is how it looks in the console:
I've checked an double checked the configuration and can't figure out what the problem is.
Any suggestions please?

Can I control which App Engine instance the cron job accesses

I have an App Engine server with two instances - the first is the main, active instance and the second is a test instance. This setup allows me to test features on existing datastore entries without screwing up the active server too much.
I'm trying to set up a cron job for a new servlet endpoint that I added on instance 2, but the cron job tries to access the default endpoint (which doesn't exist), and specifying the full url to the second instance is not allowed. Here's what I tried (3 variations):
<cronentries>
<cron>
1. <url>2-dot-my-app.appspot.com/ping</url> // doesn't work
2. <url>/ping</url> // this tries to access the default instance
3. <url>/ping</url> // tried this long-shot as well, obviously didn't work
<target>v3</target>
<schedule>every 2 minutes</schedule>
</cron>
</cronentries>
Does anybody have suggestions?
The answer was more straightforward than I thought:
<cronentries>
<cron>
<url>/ping</url>
<target>3</target>
<schedule>every 2 minutes</schedule>
</cron>
</cronentries>

Google app engine cron scheduler is not using synchronized

I want to run a cron for every 2 minutes interval, 0,2,4,6,8 .... each cron execution runs for 2 minutes.
I configured cron schedule with synchronized as below. But I still see scheduler is behaving as if synchronized not given.
Crons are scheduled at
0-2 First cron
4-6 Second cron
8-10 third cron
Cron scheduler is waiting for 2 minutes after last cron execution.
If I understand synchronized correctly, it is added to avoid this behavior.
Why this happening.
<cron>
<url>/cron/syncPrices</url>
<description>Fetch data from source and cache it in data store.</description>
<schedule>every 2 minutes synchronized</schedule>
</cron>
You can check the actual cron configuration for your application on the old GAE console in the Cron Jobs menu on the left. You're looking to confirm if synchronized (or its from 00:00 to 23:59 equivalent) is present for the respective job:
if synchronized is missing it's possible that the cron.yaml file wasn't uploaded/updated during the regular app upload - I noticed this to be the case with my multi-module (python) application. You have to specifically update the cron configuration using the update_cron option of your AppCfg utility.
if synchronized is indeed present and the unexpected behaviour continues you should open a support case with Google.
FYI It looks like 'synchronized' is no longer part of the cron.yaml documentation. I've reached out to Google via the documentation feedback link.

What could be causing my app google engine cron job not to work?

I've the following in cron.xml on my WEB-INF directory:
?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/?brtyuioacdwer</url>
<description>Load datastore</description>
<schedule>every monday 06:17</schedule>
<timezone>America/New_York</timezone>
</cron>
</cronentries>
But when the time comes to execute the shown URL nothing seems to happen as my datastore keeps the same, of course I've tested to call the URL from browser and it does its work nicely and I've uploaded new version of the app several minutes before it should be automatically executing. I don't know if there might be some problems with cron jobs when they try to write on datastore or if they are not the default version af the web application, so I'm asking for some guide.
Thanks for your attention.

how to implement Cron jobs(shedulded tasks) for a servlet in Appengine Application

I start developing Google Appengine Java Application..for that I am using Servlet, jsp and EClipse helios IDE.
In my Application, I want to create a servlet, that will execute for Particular time interval(every 5 minutes) and the the get values are stored in datastore.....
How to do this...Also i go through about Scheduling tasks here.But I didn't understand how to implement in my project using Eclipse....
Please help me.....
You just need to create a servlet that will handle requests to the URL you specify in your cron config. Your cron.xml gets saved in the same location as your appengine-web.xml.
cron job in AppEngine uses http GET, so just any servlet that handles doGet() will suffice.
suppose your servlet is mapped to /mytask in web.xml, then in cron.xml,
<cron>
<url>/mytask</url>
<description>describe your task here</description>
<schedule>every 1 minutes</schedule>
</cron>
this instructs appengine to issue a httpGet at URL /mytask every minute.

Resources