I want to do the following:
Normally you implement Play-Jobs by implementing a Class which extends the http://www.playframework.org/documentation/api/1.2.4/play/jobs/Job.html which is added to the pool OnApplicationStart…
I want to add Cron-Jobs now at Runtime (add Tasks via GUI…) but im not sure how to implement that.
I looked into the JobsPlugin and found the following lines:
job.nextPlannedExecution = nextDate;
executor.schedule((Callable<V>)job, nextDate.getTime() - now.getTime(), TimeUnit.MILLISECONDS);
job.executor = executor;
Do i have to add them like that?
Is that even possible? Cause i cant find any line, where the Job itself is told, which Cron-Expression it should follow…
String cron = job.getClass().getAnnotation(On.class).value();
Is this line called from outside again after a Job-Excecution and a new job.nextPlannedExecution is set?
Ok i hope im not answering my own question now, but could this be the solution?:
I implement my own Job-Class, add a Attribute e.g. cronExpression and overrride the Job’s
public void _finally() {
super._finally();
if (executor == JobsPlugin.executor) {
JobsPlugin.scheduleForCRON(this);
}
}
to implement my own sheduleForCron()
Looking at the source code for JobsPlugin, you should just be able to mimic what is done using the
scheduledJobsandexecutorattributes.If you take a look at the
onApplicationStartmethod, this shows how Jobs annotated with@Onor ‘@Everyare managed in the job pool.Onuses the CRON expression and usesscheduleForCRON, where asEvery` uses the executor to manage the repetition.As the
scheduledJobsandexecutorattributes are public static, you can access and maniplulate this as much as you wish, so I would suggest reading through the source code of JobsPlugin, especially the following code, and to mimic it in your own codebase.