Google App Engine's 1 minute cron limitation - java

I am using GAE Java for my web application and I need to run a scheduled task every 30 seconds. However, I know that the minimum is 1 minute. Any ideas (and possibly working example ) of how to do that? I've read that you can use Task Queues instead, but couldn't find how to schedule queue tasks.

You can "schedule tasks" by specifying when they should run. They have a parameter that tells it the delay to wait so you create 2 task queues one runs "now" (delay 0) and the other runs with 30sec delay. See the countdown property.https://developers.google.com/appengine/docs/python/taskqueue/tasks#countdown_arg
You can then have the 1minute cron do that.
However, the frontend will never sleep plus you will consume more with the task queues. You can also use a single backend and have it run 2 threads or your own scheduler in a loop. Keep a cron to restart the backend if it goes down (which will after about 15min)

Related

spring scheduler after maintenance

we are using spring sceduler using
#Scheduled(cron = "0 15 10 15 * ?")
the problem is that some time we have maintenece and the system is down when the job is sceduled to run.
is there another sceduler we can use ? maybe a parameter that checks if there was scedualed job that didnt run during maintenence and run it when the system is up?
or a recomenation for a different scedualer to use
Thanks
M. Deinum mentioned Quartz as a possible solution. It is a very advanced scheduling product that may handle scheduling for multiple nodes insuring that the job would run only on one node. It has many other features. I haven't used it in long while so you can look up if it is something you want to use.
However, I have dealt with your particular case in a simpler way. Part of the scheduled job responsibility was upon each run to write down into a DB table the last scheduled time (the one in the past that triggered the current run), the next scheduled time and the actual last execution time. Then, after a down time when the server starts up it has to check if the next scheduled time is in the past (also the last execution time will be older then the next scheduled time). If it is so, it is your flag that the the job missed its running due to down time (or any other reason). So you can reschedule or run it now
P.S. This will not address your actual problem, but I wrote my own scheduler and published it as part of an open-source library. My scheduler allows you to set the time intervals in more human readable form such as "4h" for 4 hours or "30m" for 30 minutes and so forth. Also it can handle multiple tasks scheduling and allows you to specify the number of threads that will handle all your scheduled tasks. You can read about it here. The library is called MgntUtils and you can get it as Maven artifacts or from Github repository releases (with source code and Javadoc included). You can read an article about the library that describes some of the features here

Java Schedule a task for single execution

I need to execute a task in the future, just once.
Requirements:
- The environment is clustered, so need to take care of competition in the moment that the task gets fired, it cannot execute twice;
- The task can be scheduled a month ahead and cannot be just scheduled in memory as soon as the node can be restarted or even destroyed at a certain moments (it's an Amazon Elastick Beanstalk environment);
Any suggestions will be welcome.
One idea: Instead of trying to get the cron/timer tool to only execute once, you could schedule the task on all of the nodes, but then use some kind of coordination between nodes to decide which one will actually execute the task.

Spring Scheduler Disallow Concurrent Alternative

When scheduling a task in Quartz, you have the ability to set misfires and rescheduling. This could be used in the example scenario whereby there is a job that runs every 30 mins, and potentially there could be a backlog and and the job would execute for longer than 30 mins. To prevent the same job running twice you could use the #DisallowConcurrentExecution. Once complete the job would then execute the second instance that is queued by using simpleSchedule().withMisfireHandlingInstructionNowWithExistingCount().
Now in Spring Scheduler there doesn't appear to be this fine grained ability, with just the fixed-rate and fixed-delay options to schedule it every 30 mins or wait 30 mins after the previous job completed. Without using the hammer route of restricting to a single thread, as I want to increase the thread count for other batch jobs to run concurrently, what would be the best method of recreating the Quartz behaviour?
So it looks like with the basic Spring Scheduler there isn't such a mechanism. To do this either use the Spring Quartz Scheduler, or Quartz directly.

How to wait for spring cron job to be finished from ant build script

Say my web app has two spring cron jobs scheduled to run every minute/hour. Before I'm redeploying my app I can't just shut it down, I must wait for jobs to be finished correctly. I can provide some flag in database or somewhere else, so that jobs will stop to run iteratively - every minute or hour - put some check inside job function to return/do nothing on the next trigger call if such flag checked.
But how can I wait for current job call to finish? And how to see it from ant or other outside script - to choose good time for server shutdown.
There may be solution to put some flag in db or file, and read it. But may be there is some more accurate way - jms or something like that?
Instead of using the database you can use JMX. -- But in my humble opinion: If you already use a database but no JMX yet, then use a DB flag, or a simple file, to signal the timer to "stop".
More nice than using the flag and check for every invocation if the flag is set would be shoting shutdown() down the ThreadPoolTaskSchedule or ThreadPoolTaskExecutor.
But this would require a second task (run every minute or shorter) to check the flag and then shutdown to scheduler.
To make the ant task wait for a timespan, after setting the flag, to make sure that the last task is done, you can use the WaitFor task.
If you're using a TaskExecutor to run the "cron" jobs, then you could use the method described by skaffman in this answer to get the results of the task execution. If you need access to this from ant, you could probably use spring's JMS support with ant-jms.

How to schedule multiple jobs in quartz scheduler using same trigger?

I am using quartz scheduler in my spring project. I have to run a job after another job which is scheduled to run in every 15 mins? I cant run this job concurrently as both of this jobs have to access same mail account using different protocols(one to send:smtp and other to receive: imap) and it may cause problems. Please reply quickly, as its an urgent requirement.
Just write a wrapper job class that launches second job after the first. You could then reuse separate jobs in the future if there will be any necessity.
You could do something with writing a job listener to recognize when the first job ends, and have it start the second. But the solution first suggested by mindas is easier - wrap both your jobs in another Job implementation, which is the one you actually schedule.

Categories

Resources