question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Scheduled add Support for Default Value and for Switching Timer Off

See original GitHub issue

Description

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.intevalis 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 offor 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)
  • cronand every should support the reserved values off and disabled to disable scheduling. (Better solution than: https://stackoverflow.com/questions/13835221/quartz-cron-expression-that-will-never-execute for cron and every 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:closed
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mkoubacommented, Mar 29, 2021

So should we prevent: delay="${myconf.delay}s"or every="${myconf.task1.interval:${myconf.default.interval:off}}" ?

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}.

0reactions
radcortezcommented, Mar 29, 2021

Let me know if you need help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create schedule triggers - Azure Data Factory & Azure Synapse
Specify Recurrence for the trigger. Select one of the values from the drop-down list (Every minute, Hourly, Daily, Weekly, and Monthly). Enter ...
Read more >
How do I use Instance Scheduler with CloudFormation to ...
For Instance Scheduler TagName, you can keep the default value as Schedule, or customize it. For Frequency, choose a frequency in minutes to ......
Read more >
Configure Idle Session Timeout Settings on a Switch ... - Cisco
Note: If a browser remains idle for more than the specified timeout value, the switch closes the session. The default value is 10...
Read more >
Timer - Home Assistant
This allows you to differentiate if a timer has switched from active to idle because the given duration has elapsed or it has...
Read more >
34.4 Using the Timer Service - Java Platform, Enterprise Edition
Attribute, Description, Default Value, Allowable Values and Examples ... Adding a @Schedule annotation on an enterprise bean marks that method as a timeout ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found