Schedule recurring jobs with a single line of code using any CRON expression.
Creating a recurring job is just as simple as creating a background job – you only need to write a single line of code (and it is even less if you use the jobrunr-spring-boot-starter, jobrunr-micronaut-feature or the jobrunr-quarkus-extension):
This line creates a new recurring job entry in the StorageProvider. A special component in BackgroundJobServer checks the recurring jobs on a minute-based interval and then enqueues them as fire-and-forget jobs. This enables you to track them as usual.
Remark: for recurring methods to work, at least one BackgroundJobServer should be running all the time and the jobs should be registered on startup of your application.
Also note that the smallest possible cron interval for your recurring jobs is every 5 seconds. JobRunr prevents to create recurring jobs every with cron values less than 5 seconds (e.g. every second) as it would generate too much load on your StorageProvider (SQL or noSQL database).
The Cron class contains different methods and overloads to run jobs on a minute, hourly, daily, weekly, monthly and yearly basis. You can also use standard CRON expressions to specify a more complex schedule:
All these methods are also available on the JobScheduler and JobRequestScheduler bean:
Each recurring job has its own unique identifier. In the previous examples it was generated implicitly, using the type and method names of the given call expression (resulting in “System.out.println” as the identifier). The BackgroundJob and JobScheduler class contains overloads that take an explicitly defined job identifier. This way, you can refer to the job later on.