Ktor integration
Latest stable Based on Leader release 0.4.0
Install an application-scoped suspend elector and bind periodic attempts to Ktor shutdown.
Plugin
Section titled “Plugin”LeaderElectionPlugin exposes a configured SuspendLeaderElector through the Ktor application. The application decides which backend client and elector it owns. Keep one lifecycle owner so plugin shutdown does not race a separately closed client.
Scheduling
Section titled “Scheduling”Application.leaderScheduled(lockName, period) { ... } launches periodic election attempts. Only the elected instance runs the body, and the job is cancelled on ApplicationStopped. Set lease longer than one normal iteration or use a supported extension strategy for variable work.
What remains yours
Section titled “What remains yours”The helper does not persist missed schedules, serialize retries, or make side effects idempotent. Record durable work state if a run must be recovered. Test two Ktor applications against one backend and verify both exclusive execution and shutdown cancellation.
Release sources
Section titled “Release sources”leader-ktor/src/main/kotlin/io/bluetape4k/leader/ktor/LeaderElectionPlugin.ktleader-ktor/README.mdexamples/ktor-app/src/test/kotlin/io/bluetape4k/leader/examples/ktor/KtorAppTest.kt