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(val 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

Link copied to clipboard
class LambdaKronScheduler(onNext: suspend (<ERROR CLASS>) -> <ERROR CLASS>?) : KronScheduler
Link copied to clipboard
class LambdaKronSchedulerTz(onNext: suspend (<ERROR CLASS>) -> <ERROR CLASS>?) : KronSchedulerTz

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 (<ERROR CLASS>) -> Unit)

Will execute block without any checking of result

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

Will buildSchedule using scheduleConfig and call doInfinity with block

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

Will execute block without any checking of result

inline suspend fun doInfinityTz(scheduleConfig: String, noinline block: suspend (<ERROR CLASS>) -> Unit)

Will buildSchedule using scheduleConfig and call doInfinity with block

Link copied to clipboard
inline suspend fun <T> KronScheduler.doOnce(noinline block: suspend (<ERROR CLASS>) -> 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 (<ERROR CLASS>) -> T): T

Will buildSchedule using scheduleConfig and call doOnce on it

Link copied to clipboard
inline suspend fun <T> KronScheduler.doOnceTz(noinline block: suspend (<ERROR CLASS>) -> 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 (<ERROR CLASS>) -> T): T

Will buildSchedule using scheduleConfig and call doOnce on it

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

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

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

Will buildSchedule using scheduleConfig and call doWhile with block

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

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

inline suspend fun doWhileTz(scheduleConfig: String, noinline block: suspend (<ERROR CLASS>) -> 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
fun KronScheduler(onNext: suspend (<ERROR CLASS>) -> <ERROR CLASS>?): LambdaKronScheduler
Link copied to clipboard
fun KronSchedulerTz(onNext: suspend (<ERROR CLASS>) -> <ERROR CLASS>?): LambdaKronSchedulerTz
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: <ERROR CLASS>): <ERROR CLASS>
Link copied to clipboard
suspend fun KronScheduler.nextOrNow(): <ERROR CLASS>
Link copied to clipboard
suspend fun KronSchedulerTz.nextOrNowWithOffset(): <ERROR CLASS>
Link copied to clipboard
suspend fun KronScheduler.nextOrRelative(relatively: <ERROR CLASS> = DateTime.now()): <ERROR CLASS>
suspend fun KronSchedulerTz.nextOrRelative(relatively: <ERROR CLASS>): <ERROR CLASS>
Link copied to clipboard
suspend fun KronScheduler.nextTimeZoned(): <ERROR CLASS>?
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 EveryMillisecondScheduler: KronScheduler

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

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