running a cron job just once - java

how can we schedule a cron job to run just once on google app engine for java?
i tried to set a very large value like every 1000 years but doesnt seems to work.
any other option? syntax used is:
<cron>
<url>/AdHocScriptJob</url>
<description>Run adhoc script</description>
<schedule>every 200 minutes</schedule>
<timezone>Asia/Calcutta</timezone>
</cron>
i tried to look at https://developers.google.com/appengine/docs/java/config/cron

That's what task queues are for: https://developers.google.com/appengine/docs/java/taskqueue/overview
Alternatively, you may delete the cron configuration after the task executes or make your code idempotent (e.g. by mixing it with a pull queue).

Related

GAE cron job shuts down unexpectedly

I have some cron jobs configured in cron.xml in an application on Google App Engine.
These jobs work once a day on a version of my application and make some work on the db.
For example a cron job calls v1.myapp.appspot.com...
After some weeks this application instance seems to no longer work correctly. It does not execute the cron jobs as I expect.
On GAE Dashboard I found a section with a list of cron job, but I can't see my cron jobs there.
Why did they disapper? What's wrong with my configuration environment? or Why google stops the execution of my cron jobs?
The cron job configuration is an app-wide scope configuration, it's not a configuration of a specific service/version. Every cron deployment (which can be done without necessarily updating a service/version) will overwrite the previously deployed one.
To avoid accidental errors personally I have a single cron config file at the app level, symlinked inside each service as needed.
If you want to keep the cron job for an older version running you need to add a configuration entry for it with a target matching that service/version, otherwise the cron job will stop working when that version is no longer the default one (as the cron-triggered requests will be directed towards the default service/version):
From Creating a cron job:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/tasks/summary</url>
<target>beta</target>
<description>daily summary job</description>
<schedule>every 24 hours</schedule>
</cron>
</cronentries>
The target specification is optional and is the name of a
service/version. If present, the target is prepended to your app's
hostname, causing the job to be routed to that service/version. If no
target is specified, the job will run in the default version of the
default service.

how to set cron job with http-post on google-app-engine?

I have set a google-cloud cron job like this:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/match</url>
<description>bla bla</description>
<schedule>every 2 minutes</schedule>
</cron>
</cronentries>
but i see in the google cloud console it sends a "get"
how can i change it to "post" ?
You can't. From Scheduling Tasks With Cron for Java (emphasis mine):
A cron job invokes a URL, using an HTTP GET request, at a given
time of day. An cron job request is subject to the same limits as
those for push task queues.
If you really, really need a POST you can trigger one from inside your cron job itself.

How to kill quartz scheduled threads?

I had added quartz scheduler code earlier in our application and now I have removed that code.
The job was scheduled to run every hour.
But now I have removed that code and deployed new war which does not have that code.
But now also I can see logs like below every one hour,
10:00:00.001 [org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-4]
How to kill these threads?
If you are making use of quartz jdbcstore, you need to delete the trigger and job detail records from database.

Monitor google app engine cron jobs in console?

This might be a dumb question, but, i just can't find cron jobs panel, I've got an app in java and I need to refresh the data every day, so I create this cron.xml inside WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/refreshdata</url>
<description>Daily data refresh cron task </description>
<schedule>every day 05:00</schedule>
</cron>
</cronentries>
I deployed it, but it doesnt work and I cant find the "cron job panel" in console to monitor it or even check if GAE recognizes it...
Documentation says " (You can verify the Cron job you just deployed by clicking Cron Jobs in the left nav pane.) http://i.stack.imgur.com/1niVt.png "
but it doesn't exist anymore, gae's console UI changed, where it is now? I tried in logs without success
it is something wrong with my .xml?
Any help would be apreciated, thanks.
If you are using the new Console for your projects in app engine then this is how it will look like after you have selected a project to view from https://console.developers.google.com/project using your google account.
Hope it helps!
You can find it under Task Queues, you should be able to see Cron as a tab in that view
On Cloud developers console, it should be available at this location:
https://console.developers.google.com/project/your-project-id/appengine/taskqueues?tab=CRON

GAE : How to configure backends.xml for long time working process

In my java application i'm processing one lack data per day using cron job but it cannot be properly do with cron jobs (DeadLineExceedException) and 10 minute is not enough to complete the process. So i would like switch the process to backends.xml. But i don't know how to move backends.xml. How can i start the process at a fixed time after moving to backends.
If I understand it correctly, you want your Cron jobs to be executed at your backend in order to have a longer deadline in processing jobs. You can add <target>[backend_version]</target> on the cron job definition in your cron.xml in order to have the cron executed at a specific version of your app.
Combined with your backends.xml file, this means that you could configure both files as per the following examples:
backends.xml
<backends>
<backend name="longtimeworker">
<class>B1</class>
<instances>1</instances>
</backend>
and
cron.xml
<cronentries>
<cron>
<url>/longtimeworkingprocesshandler</url>
<schedule>every 12 hours</schedule>
<target>longtimeworker</target>
</cron>
That way, you can configure your cron to be executed at the longtimeworker backend.

Categories