Package dev.inmo.krontab

Types

KronScheduler
Link copied to clipboard
common
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

KronSchedulerTz
Link copied to clipboard
common
interface KronSchedulerTz : KronScheduler

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

KronSchedulerWork
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

KrontabTemplate
Link copied to clipboard
common
typealias KrontabTemplate = String
KrontabTemplateSchedulerWork
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

KrontabTemplateWrapper
Link copied to clipboard
common
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

buildSchedule
Link copied to clipboard
common
fun buildSchedule(incoming: KrontabTemplate): KronScheduler
fun buildSchedule(incoming: KrontabTemplate, defaultOffset: Minutes): KronSchedulerTz
createSimpleScheduler
Link copied to clipboard
common
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
doInfinity
Link copied to clipboard
common
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

doInfinityLocal
Link copied to clipboard
common
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

doInfinityTz
Link copied to clipboard
common
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

doOnce
Link copied to clipboard
common
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

doOnceLocal
Link copied to clipboard
common
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.

doOnceTz
Link copied to clipboard
common
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

doWhile
Link copied to clipboard
common
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

doWhileLocal
Link copied to clipboard
common
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

doWhileTz
Link copied to clipboard
common
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

enqueueKronSchedulerWork
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

enqueueKrontabTemplateSchedulerWork
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

merge
Link copied to clipboard
common
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
next
Link copied to clipboard
common
suspend fun KronScheduler.next(relatively: DateTimeTz): DateTimeTz?
nextOrNow
Link copied to clipboard
common
suspend fun KronScheduler.nextOrNow(): DateTime
nextOrNowWithOffset
Link copied to clipboard
common
suspend fun KronSchedulerTz.nextOrNowWithOffset(): DateTimeTz
nextOrRelative
Link copied to clipboard
common
suspend fun KronScheduler.nextOrRelative(relatively: DateTime = DateTime.now()): DateTime
suspend fun KronSchedulerTz.nextOrRelative(relatively: DateTimeTz): DateTimeTz
nextTimeZoned
Link copied to clipboard
common
suspend fun KronScheduler.nextTimeZoned(): DateTimeTz?
toKronScheduler
Link copied to clipboard
common
fun KrontabTemplate.toKronScheduler(): KronScheduler
fun KrontabTemplate.toKronScheduler(defaultOffset: Minutes): KronSchedulerTz

Shortcut for buildSchedule

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

Shortcut for buildSchedule

wrapAsKronScheduler
Link copied to clipboard
common

Will create KrontabTemplateWrapper from this

Properties

AnyTimeScheduler
Link copied to clipboard
common
val AnyTimeScheduler: KronScheduler

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

EveryDayOfMonthScheduler
Link copied to clipboard
common
val EveryDayOfMonthScheduler: KronScheduler

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

EveryHourScheduler
Link copied to clipboard
common
val EveryHourScheduler: KronScheduler

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

EveryMinuteScheduler
Link copied to clipboard
common
val EveryMinuteScheduler: KronScheduler

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

EveryMonthScheduler
Link copied to clipboard
common
val EveryMonthScheduler: KronScheduler

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

EverySecondScheduler
Link copied to clipboard
common
val EverySecondScheduler: KronScheduler

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

EveryYearScheduler
Link copied to clipboard
common
val EveryYearScheduler: KronScheduler

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

krontabTemplateWorkField
Link copied to clipboard
const val krontabTemplateWorkField: String