ShedLock
ShedLock copied to clipboard
LockAtLeastFor not respected?
Describe the bug
- Which version do you use:
5.13.0
- Which Lock Provider:
shedlock-provider-jdbc-micronaut
- ShedLock configuration: see code below
- ShedLock logs: see below
Expected behavior Not sure if this is a bug or me mis-understanding.
Given the code below, I was expecting when 2 processing running in parallel, the task would only be executed once due to the LockAtLeastFor
set to 1 second.
val txManager = DataSourceTransactionManager(dataSource)
val lockProvider = MicronautJdbcLockProvider(txManager)
val executor = DefaultLockingTaskExecutor(lockProvider)
val lockConfiguration = LockConfiguration(
Instant.now(), "foo", Duration.ofSeconds(1), Duration.ofSeconds(1))
val f = File("/tmp/log2.txt")
val uuid = UUID.randomUUID().toString()
val executorService = Executors.newScheduledThreadPool(1)
val command = Runnable {
executor.executeWithLock(
Runnable {
"[${Instant.now()}|$uuid] Executed!".also {
f.appendText("$it\n")
println(it)
}
},
lockConfiguration)
}
executorService.scheduleAtFixedRate(command, 0, 1, TimeUnit.SECONDS)
Actual behavior Each process is executing the same task every 1 second:
[2024-07-16T11:55:07.206796Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:07.232144Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!
[2024-07-16T11:55:08.211072Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:08.233553Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!
[2024-07-16T11:55:09.204585Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:09.233596Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!
[2024-07-16T11:55:10.217054Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:10.236675Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!
[2024-07-16T11:55:11.210968Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:11.236006Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!
[2024-07-16T11:55:12.209571Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:12.234226Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!
[2024-07-16T11:55:13.208047Z|531c4486-4a99-44cd-8ed7-0e99221b53af] Executed!
[2024-07-16T11:55:13.231663Z|650af8e8-68ca-4e6a-99c7-4a4a25b8ccdf] Executed!