How to set a complex custom crontab in google-app-engine (java)? - java

I am building an app for which I need to set up cron jobs. What I want to do is to set the specific minutes in a hour where specific crons should run. For instance:
Task1 at 1st minute of the hour
Task2 on every second minute of the hour
Task3 every 2 minute only in the second half of the hour
Building this in the standard Unix cron format is reasonably straightforward, but could not figure out how to do it in the Google-App-Engine.
The documentation does not list any non-trivial examples. Any suggestions on how to do it? Examples would be excellent.

The documentation you linked to seems to indicate that it isn't possible to do what you want using only Cron for Java (unless they have an undocumented feature for it). In particular this doesn't appear to allow for multiple times.
time specifies the time of day, as HH:MM in 24 hour time.
The Python version says the exact same thing.
However, one solution (albeit somewhat more expensive in terms of CPU usage) would be to call a URL every minute, and from the handler for that URL, dispatch out to whatever other calls you need.
In other words, something like:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/run-scheduled-tasks</url>
<description>Run all scheduled tasks</description>
<schedule>every 1 minutes</schedule>
</cron>
</cronentries>
Then in run-scheduled-tasks, check a database for when each task last run, and if your complex condition for triggering them has occurred since then.

If the documentation is correct you can't get as granular as you are wanting. Doesn't look like they support picking a particular minute of the hour. Or a subset of an hour.
You might have to get creative. Why do you need such specific timing?

This may seem silly. Write three servlet. And schedule them from another UNIX machine on the other part of the world :D. Or even you can write a java app to do it. enjoy

Have a look at Quartz and see if that'll solve your problem.

Related

cron library for java with 'spreading'

I'm looking for a cron scheduling system with the possibility to 'spread out' tasks. Lets say I need to do a bit of work at 'round about' 12 o clock. The 'round about' is defined as lets say +/- 30 minutes. I need such a thing for my automated update task to not have all my millions of customers (joking...) downloading updates at exact the same time and just blowing up my webserver...
I know little about the existing cron libraries in java. I know there are cronj or quarz and dozen other systems - but I can't find out if one of them is able to do what I'm looking for.
At least I can implement such a 'spreading' feature (don't know how to call it better) myself by using a normal cron job and trigger a new Plain-Old-TimerTask with a little bit of Math.round() thingy... But would be nice if there is a native possibility for this.
Thanks and greetings
This looks being easy to implement on your own.
Create a worker thread which gets a random timer, sleeps and wakes up.

AppEngine/Java Cron DeadlineExceededException

I have cron setup in appengine project:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/cron/someurl</url>
<description>cron</description>
<schedule>every monday 8:00</schedule>
<timezone>Asia/Singapore</timezone>
</cron>
</cronentries>
I am getting the error:
com.google.apphosting.api.DeadlineExceededException: This request (40811df3b6350a70) started at 2012/11/26 00:00:00.404 UTC and was still executing at 2012/11/26 00:09:59.917 UTC.
It's a 1-minute limit to run the task? I though cron doesn't have that limit. How to avoid the error in cron entry?
Thanks.
An HTTP request invoked by cron can run for up to 10 minutes, as per the documentation. If you notice the exception log closely in the HH:MM:SS value, you will find that a total of 10 minutes have passed since the job was started.
You might want to look at your code to see why it is taking that long. In case you have requirements that make your tasks run longer than 10 minutes, I suggest that you look at trapping the exception and then inserting another request to run a job with some request parameter that tells the job to start from where it left off last time.
Alternately, you could also look at Backends.
Also you can try using task queues (10 minute maximun) and re-enqueue when you are near to time limit, using for that any state variable stored in datastore, or if you are depending of a iteration in datastore you can pass the datastore cursor to the other re-enqueued task. For me that works very well.

A way to have a task run according to a given schedule

I'm about to create a small application which will be responsible for sending out various reports to various users at various intevals. We might be talking about 50 or 100 different reports going to different people. Some reports needs to be generated every day, some every week, and some every month.
I've been using the Quartz library earlier to run tasks at regular intervals. However, in order to keep things simple I like the thought of having a single Quartz thread taking care of all reports. That is, the thread should loop through all reports, say every 15 minutes, and determine wether it is time for one or more to be generated and sent. It does not matter if a report is generated at 12:00 or 12:15.
I'm thinking about wether it would be possible, somehow, for each report to set up specific times such as "mon#12:00,wed#12:00" or "fri#09:30". Then, based on that, the thread would determine if it was time to send a report or not.
My question is; has anyone else done something like this and does any libraries exist which can make it easy to implement this task?
why not simply register a separate quartz task instance for each report and let Quartz handle all the scheduling for you? That is after all the point behind it.
you can create just single thread and it would ping a "job schedule data structure" at some time interval to see if it needs to run a report. If yes, it would run the report, otherwise, it would go for a short nap and ping again after specified sleep time.
It will cause problem if one job takes too much time to complete and you start accumulating jobs.
The job schedule data structure would keep its record sorted by time stamp.

Quartz misfiring policies

I'm new to Quartz in java and I have a question regarding misfiring.
I have set up a SimpleTrigger which fires every 5 seconds. Sometimes the associated job takes over 5 seconds. I'd like to skip the job when that happens (the set interval has been reached by the Trigger). Going through the API I dont find a misfiring policy that would do that.
Any toughts?
Thank you for the help
There are a couple of different misfire policies that could work for you. Look at the javadocs here: http://www.quartz-scheduler.org/docs/api/1.8.0/org/quartz/SimpleTrigger.html paying attention to the static final constants that start with MISFIRE_INSTRUCTION_RESCHEDULE_*. There are a number of different behaviors in regards to the repeat count, but I think they'll accomplish what you're trying to do.

Dynamic time scheduling advice

I am using Jboss5.1.x, EJB3.0, Quartz 1.8
I have System which is being activated at specific time(surrounding that time).
The system should work once in a day.
I am setting value in a database which mention the activation time and every hour the system is pulling that value to check if the current time is matching the value (in case it is the system will activate itself).
This time has to be changeable in the future dynamiclly.
Now this technic gives me a headache, since I need to do some Math calculations (in case the current time has passed in couple of mins I still need to activate the system.
more over I need to take care for a case the system already activated so it wont be activated again in the same day (due to a time mistake caluclations.)
I could think about other technic which pulling the database once in couple of days to check if the activiation time has ever change(in this case I wont need to pull every hour, but in other case i am not sure Quartz can re-schedualre it's triggers while it's running)
any ideas? solutions?
Thanks,
ray.
You absolutely can reschedule triggers while Quartz is running (or add new triggers).
You can even do that from within the executing jobs if you like.
This a great example for my solution:
Dynamic time scheduling advice

Categories

Resources