KronosStore

interface KronosStore

Storage abstraction used by Kronos. Implement this interface to add a new backend.

The default implementation is MongoKronosStore from the kronos-mongo artifact. Implementations are responsible for both persistence and any caching strategy they choose.

Functions

Link copied to clipboard
abstract suspend fun acquireLock(id: String): KronoJob?

Atomically increment the locks counter on the job with this id. Returns the job or null if the document no longer exists. A null return signals that execution should be aborted.

Link copied to clipboard
open fun close()

Release any held resources (connections, scopes). Called on Kronos.shutDown.

Link copied to clipboard
abstract suspend fun countByName(name: String): Long

Return the count of jobs with the given name.

Link copied to clipboard
abstract suspend fun delete(id: String): KronoJob?

Delete the job with this id. Returns the deleted job (used for callback dispatch) or null if it did not exist.

Link copied to clipboard
abstract suspend fun deleteAll(): Boolean

Delete all jobs. Returns true if acknowledged.

Link copied to clipboard
abstract suspend fun deleteByName(name: String): Boolean

Delete all jobs with the given name. Returns true if acknowledged.

Link copied to clipboard
abstract suspend fun fetchDueJobs(nowMs: Long): List<KronoJob>

Return jobs eligible to run right now: startTime <= nowMs and locks == 0. This query runs every minute — it must be efficient (index-backed).

Link copied to clipboard
abstract suspend fun findAll(): List<KronoJob>

Return all scheduled jobs.

Link copied to clipboard
abstract suspend fun findById(id: String): KronoJob?

Retrieve a single job by its ID, or null if not found.

Link copied to clipboard
abstract suspend fun findByName(name: String): List<KronoJob>

Return all scheduled jobs with the given name.

Link copied to clipboard
abstract suspend fun initialize()

Called once at startup — create indexes, run schema migrations, etc.

Link copied to clipboard
abstract suspend fun insert(job: KronoJob): KronoJob?

Persist a new job. Returns the inserted job, or null if insertion failed.