Package dev.inmo.krontab

Types

Link copied to clipboard
interface KronScheduler

This interface was created for abstraction of next operation. Currently, there is only dev.inmo.krontab.internal.CronDateTimeScheduler realisation of this interface inside of this library, but you it is possible to create your own realisation of this interface for scheduling, for example, depending of users activity or something like this

Link copied to clipboard
interface KronSchedulerTz : KronScheduler

This interface extending KronScheduler to use DateTimeTz with taking into account offset of incoming time for next operation.

Link copied to clipboard
abstract class KronSchedulerWork(context: Context, workerParams: WorkerParameters) : CoroutineWorker

Use this class as a super class in case you wish to implement krontab-based enqueuing of works

Link copied to clipboard
typealias KrontabTemplate = String
Link copied to clipboard
abstract class KrontabTemplateSchedulerWork(context: Context, workerParams: WorkerParameters) : KronSchedulerWork

Extend this class in case you wish to base on KrontabTemplate. It will automatically handle request of kronScheduler and put it in setUpRequest

Link copied to clipboard
data class KrontabTemplateWrapper(template: KrontabTemplate) : KronScheduler

This class contains template and can be simply serialized/deserialized. In fact that class will work as dev.inmo.krontab.internal.CronDateTimeScheduler due to the fact that toKronScheduler will return it under the hood

Functions

Link copied to clipboard
fun buildSchedule(incoming: KrontabTemplate): KronScheduler
fun buildSchedule(incoming: KrontabTemplate, defaultOffset: Minutes): KronSchedulerTz
Link copied to clipboard
fun createSimpleScheduler(incoming: KrontabTemplate): KronScheduler

Parse incoming string and adapt according to next format: "* * * * *" where order of things:

fun createSimpleScheduler(incoming: KrontabTemplate, defaultOffset: Minutes): KronSchedulerTz
Link copied to clipboard
inline suspend fun KronScheduler.doInfinity(noinline block: suspend () -> Unit)

Will execute block without any checking of result

inline suspend fun doInfinity(scheduleConfig: String, noinline block: suspend () -> Unit)

Will buildSchedule using scheduleConfig and call doInfinity with block

Link copied to clipboard
inline suspend fun KronScheduler.doInfinityLocal(noinline block: suspend (DateTime) -> Unit)

Will execute block without any checking of result

inline suspend fun doInfinityLocal(scheduleConfig: String, noinline block: suspend (DateTime) -> Unit)

Will buildSchedule using scheduleConfig and call doInfinity with block

Link copied to clipboard
inline suspend fun KronScheduler.doInfinityTz(noinline block: suspend (DateTimeTz) -> Unit)

Will execute block without any checking of result

inline suspend fun doInfinityTz(scheduleConfig: String, noinline block: suspend (DateTimeTz) -> Unit)

Will buildSchedule using scheduleConfig and call doInfinity with block

Link copied to clipboard
inline suspend fun <T> KronScheduler.doOnce(noinline block: suspend () -> T): T

Execute block once at the KronScheduler.next time and return result of block calculation.

inline suspend fun <T> doOnce(scheduleConfig: String, noinline block: suspend () -> T): T
inline suspend fun <T> doOnce(scheduleConfig: String, noinline block: suspend (DateTime) -> T): T

Will buildSchedule using scheduleConfig and call doOnceLocal on it

Link copied to clipboard
inline suspend fun <T> KronScheduler.doOnceLocal(noinline block: suspend (DateTime) -> T): T

Execute block once at the KronScheduler.next time and return result of block calculation.

Link copied to clipboard
inline suspend fun <T> KronScheduler.doOnceTz(noinline block: suspend (DateTimeTz) -> T): T

Execute block once at the KronScheduler.next time and return result of block calculation.

inline suspend fun <T> doOnceTz(scheduleConfig: String, noinline block: suspend (DateTimeTz) -> T): T

Will buildSchedule using scheduleConfig and call doOnceLocal on it

Link copied to clipboard
inline suspend fun KronScheduler.doWhile(noinline block: suspend () -> Boolean)

Will execute block while it will return true as a result of its calculation

inline suspend fun doWhile(scheduleConfig: String, noinline block: suspend () -> Boolean)

Will buildSchedule using scheduleConfig and call doWhile with block

Link copied to clipboard
inline suspend fun KronScheduler.doWhileLocal(noinline block: suspend (DateTime) -> Boolean)

Will execute block while it will return true as a result of its calculation

inline suspend fun doWhileLocal(scheduleConfig: String, noinline block: suspend (DateTime) -> Boolean)

Will buildSchedule using scheduleConfig and call doWhile with block

Link copied to clipboard
inline suspend fun KronScheduler.doWhileTz(noinline block: suspend (DateTimeTz) -> Boolean)

Will execute block while it will return true as a result of its calculation

inline suspend fun doWhileTz(scheduleConfig: String, noinline block: suspend (DateTimeTz) -> Boolean)

Will buildSchedule using scheduleConfig and call doWhile with block

Link copied to clipboard
inline suspend fun <T : KronSchedulerWork> Context.enqueueKronSchedulerWork(workName: String, initialScheduler: KronScheduler, existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.REPLACE, noinline setUpRequest: suspend OneTimeWorkRequest.Builder.() -> Unit = {}): Operation?

This method is shortcut for enqueueKronSchedulerWork with reified T

inline suspend fun <T : KronSchedulerWork> Context.enqueueKronSchedulerWork(workName: String, delayMillis: Long, existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.REPLACE, noinline setUpRequest: suspend OneTimeWorkRequest.Builder.() -> Unit = {}): Operation

This method is shortcut for enqueueKronSchedulerWork with reified T parameter

suspend fun <T : KronSchedulerWork> Context.enqueueKronSchedulerWork(workName: String, initialScheduler: KronScheduler, workClass: Class<T>, existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.REPLACE, setUpRequest: suspend OneTimeWorkRequest.Builder.() -> Unit = {}): Operation?

This method is shortcut for enqueueKronSchedulerWork with initialScheduler. It will try to calculate delay by itself. In case if KronScheduler.next of initialScheduler will return null, work WILL NOT be enqueued

suspend fun <T : KronSchedulerWork> Context.enqueueKronSchedulerWork(workName: String, delayMillis: Long, workClass: Class<T>, existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.REPLACE, setUpRequest: suspend OneTimeWorkRequest.Builder.() -> Unit = {}): Operation

This method will enqueue OneTimeWorkRequest with workName and existingWorkPolicy. Use setUpRequest callback in case you need some additional actions to do before request will be enqueued

Link copied to clipboard
inline suspend fun <T : KrontabTemplateSchedulerWork> Context.enqueueKrontabTemplateSchedulerWork(workName: String, krontabTemplate: KrontabTemplate, existingWorkPolicy: ExistingWorkPolicy = ExistingWorkPolicy.REPLACE, noinline setUpRequest: suspend OneTimeWorkRequest.Builder.(data: Data) -> Unit = {}): Operation?

Will enqueueKronSchedulerWork with KronScheduler from krontabTemplate and call setUpRequest on setting up OneTimeWorkRequest.Builder with Data which will be used to OneTimeWorkRequest.Builder.setInputData after setUpRequest completed

Link copied to clipboard
inline fun Iterable<KronScheduler>.merge(): CollectionKronScheduler
fun Iterator<KronScheduler>.merge(): CollectionKronScheduler

Create new one CollectionKronScheduler to include all KronSchedulers of this

inline fun merge(vararg kronDateTimeSchedulers: KronScheduler): CollectionKronScheduler
Link copied to clipboard
suspend fun KronScheduler.next(relatively: DateTimeTz): DateTimeTz?
Link copied to clipboard
suspend fun KronScheduler.nextOrNow(): DateTime
Link copied to clipboard
suspend fun KronSchedulerTz.nextOrNowWithOffset(): DateTimeTz
Link copied to clipboard
suspend fun KronScheduler.nextOrRelative(relatively: DateTime = DateTime.now()): DateTime
suspend fun KronSchedulerTz.nextOrRelative(relatively: DateTimeTz): DateTimeTz
Link copied to clipboard
suspend fun KronScheduler.nextTimeZoned(): DateTimeTz?
Link copied to clipboard
fun KrontabTemplate.toKronScheduler(): KronScheduler
fun KrontabTemplate.toKronScheduler(defaultOffset: Minutes): KronSchedulerTz

Shortcut for buildSchedule

Link copied to clipboard
fun KrontabTemplate.toSchedule(): KronScheduler
fun KrontabTemplate.toSchedule(defaultOffset: Minutes): KronSchedulerTz

Shortcut for buildSchedule

Link copied to clipboard

Properties

Link copied to clipboard
val AnyTimeScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now

Link copied to clipboard
val EveryDayOfMonthScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now + one day

Link copied to clipboard
val EveryHourScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now + one hour

Link copied to clipboard
val EveryMinuteScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now + one minute

Link copied to clipboard
val EveryMonthScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now + one month

Link copied to clipboard
val EverySecondScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now + one second

Link copied to clipboard
val EveryYearScheduler: KronScheduler

KronScheduler.next will always return com.soywiz.klock.DateTime.now + one year

Link copied to clipboard
const val krontabTemplateWorkField: String