@Scheduled add Support for Default Value and for Switching Timer Off
See original GitHub issueDescription
The @Scheduled
annotation currently allows the attributes cron
, every
and delayed
to contain a fix value or reference a property value by an expression {propertyname}
.
I suggest to offer a default value for the property expression: e.g. @Scheduled(every = "{mytask.interval:5m}")
-> If the property mytask.inteval
is null
then the default value 5m
is used.
Also it is sometimes helpful to be able to switch a specific job off (e.g. on specific nodes). I suggest that if the property expression results in off
or disabled
, the timer for that scheduled task is switched off: @Scheduled(every = "{mytask.interval:5m}")
if mytask.inteval
is off
the task will not be scheduled.
More examples:
mytask.interval=null
: @Scheduled(every = "{mytask.interval:off}")
-> disabled
mytask.interval=off
: @Scheduled(every = "{mytask.interval:5m")}
-> disabled
mytask.interval=null
: @Scheduled(every = "{mytask.interval:5m}")
-> scheduled every 5m
mytask.schedule=off
: @Scheduled(cron = "{mytask.schedule:0/2 0/2 0 ? * * *")}
-> disabled
mytask.delayed=null
: @Scheduled(every= "5m", delayed = "{mytask.delayed:1m}")
-> scheduled every 5m with an initial delay of 1m.
- all
String
attributes of the@Scheduled
annotation should support null defaults (similar to Wildfly property-replacement) cron
andevery
should support the reserved valuesoff
anddisabled
to disable scheduling. (Better solution than: https://stackoverflow.com/questions/13835221/quartz-cron-expression-that-will-never-execute forcron
andevery
cannot be switched off yet)- Besides of the current property expression the JBoss/Wildfly style
${property}
expression could be supported, too - Optionally nested expressions could be supported:
@Scheduled(every = "{mytask.interval:{global.defaultInterval:off}}
) - Optionally property substitution could be used for substrings:
mytask.minutes='15,30,45'
:@Scheduled(cron = "0 {mytask.minutes} * ? * *")
-> cron =0 15,30,45 * ? * *
Implementation ideas
As property expressions are a general feature. This should probably be implemented consistently by different extensions. The current implementation is located in io.quarkus.scheduler.runtime.util.SchedulerUtils
and only supports a single property value lookup.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Well, I don’t think we need to prevent this. We could just mention that the syntax follows the SM expression rules, add a link, and only show the simple examples, i.e.
${my.conf.delays:10s}
or{my.conf.delays:off}
.Let me know if you need help.