Closed driessamyn closed 1 month ago
The default polling interval for new jobs is 10 seconds. If you need shorter delays, you need to configure the scheduler accordingly using .pollingInterval(Duration)
with a duration that's shorter than your minimum delay. I think to reliably trigger at your interval, it needs to be no longer than half your minimum delay...
Thanks @nicktar.
That works perfectly 👍
For completeness, here's this is the version that works:
val f = File("/tmp/log.txt")
val id = UUID.randomUUID().toString()
val shortIntervalTask = Tasks.recurring("my-task", FixedDelay.of(Duration.ofMillis(500)))
.execute { _: TaskInstance<*>, _: ExecutionContext? ->
"[${Instant.now()}|$id] Executed!".also {
f.appendText("$it\n")
println(it)
}
}
val scheduler = Scheduler.create(dataSource)
.pollingInterval(Duration.ofMillis(250))
.startTasks<RecurringTask<*>>(shortIntervalTask)
.threads(15)
.build()
scheduler.start()
Example log (4 concurrent instances):
[2024-07-18T13:42:48.417646Z|5dbe8c42-7edb-4dee-91d8-f6a28ffc0334] Executed!
[2024-07-18T13:42:48.927126Z|5dbe8c42-7edb-4dee-91d8-f6a28ffc0334] Executed!
[2024-07-18T13:42:49.437913Z|5dbe8c42-7edb-4dee-91d8-f6a28ffc0334] Executed!
[2024-07-18T13:42:49.948168Z|5dbe8c42-7edb-4dee-91d8-f6a28ffc0334] Executed!
[2024-07-18T13:42:50.482727Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:50.990114Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:51.499913Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:52.008399Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:52.518156Z|c709b11d-f787-4bd8-8d12-fe2c07c00063] Executed!
[2024-07-18T13:42:53.025445Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:53.535962Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:54.048378Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:54.559758Z|a4a16633-4e6d-4612-b040-d9482e24f395] Executed!
[2024-07-18T13:42:55.174521Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:55.684807Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:56.193730Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:56.707297Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:57.216028Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:57.726570Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:58.237484Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:58.747589Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:59.255246Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:42:59.761781Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
[2024-07-18T13:43:00.270595Z|852339ed-f0ba-4505-8869-6395bf3dd16e] Executed!
Prerequisites
Expected Behavior
Using the example code below, I was expecting a task execution every 500ms.
Current Behavior
Using the example code below I can see a task execution every 10 seconds (see logs).
Steps to Reproduce the bug
Context
Logs
Code