Scheduler

hexagon_scheduler

Provides repeated tasks execution based on Cron expressions for Hexagon framework. It uses the Cron-utils Java Library.

Note

In some platforms (i.e.: Kubernetes) there is a way to execute repeated tasks, you could take advantage of them, as using your own service will raise problems scaling those services' instances (you will have to coordinate them).

This feature does not include any sort of synchronization if you have many instances of a scheduler service. If you want your scheduled jobs to be executed just once, you have to take care of synchronization yourself.

Install Dependency

1
2
3
4
5
repositories {
    mavenCentral()
}

implementation("com.hexagonkt:hexagon_scheduler:$hexagonVersion")
1
2
3
4
5
<dependency>
  <groupId>com.hexagonkt</groupId>
  <artifactId>hexagon_scheduler</artifactId>
  <version>$hexagonVersion</version>
</dependency>

Example

You can check a usage example in the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
val cron = CronScheduler()
val times = 1
var count = 0

// Increments the counter by one each second
cron.schedule("0/1 * * * * ?") {
    count++
}

sleep((times * 1_000) + 100L)
cron.shutdown()
assert(count == times)

Packages

Name Summary
com.hexagonkt.scheduler Classes for scheduling blocks of code repeatedly based on a Cron expression.

Index

All Types

Comments