I have a large number of tasks running on cron schedules, using Spring Boot's scheduling libraries. However, I want to cause these schedules to not run on specific days (e.g. a nation strike or a government election).
He have a database containing such calendars, which are kept up-to-date. My intention was to override CronExpression#next() by first running super.next(temporal)
then comparing the result on a check against my database and then returning a modified Temporal
if the super.next()
would result on a run on a public holiday. I would assume, that my CronTrigger
would obey the next run according to my overriden CronExpression
.
What I cannot figure out is where CronExpression
is used? The CronExpression
API doc says;
See Also: CronTrigger
The CronTrigger API description says;
Trigger implementation for cron expressions. Wraps a CronExpression.
However, all of this API's constructors use String
. Why not CronExpression
? So, where is the connection between these two classes? (How can I have CronTigger
use an overridden CronExpression
?).
The only alternative that I can see is that I create abstract
class for Runnable
, then have it's run()
call my database. After which, I re-code my existing tasks to extend
this abstract
class's run()
and return
immediately on a public holiday, otherwise run as before.