Library for using Crontab-like syntax in scheduling of some Kotlin Coroutines tasks to do from time to time
Go to file
InsanusMokrassar 1d1dd4719e fill readme 2019-10-15 12:49:41 +06:00
gradle/wrapper add CronDateTime related to klock 2019-10-04 23:47:20 +06:00
src/commonMain/kotlin/com/insanusmokrassar/krontab rewrite all onto KronScheduler 2019-10-10 16:43:52 +06:00
.gitignore updates 2019-10-08 23:42:50 +06:00
LICENSE Initial commit 2019-05-21 11:35:07 +08:00
README.md fill readme 2019-10-15 12:49:41 +06:00
build.gradle updates 2019-10-08 23:42:50 +06:00
gradle.properties replace code into another package and modify publish script and properties file 2019-10-08 23:17:51 +06:00
gradlew init 2019-05-21 18:14:09 +08:00
gradlew.bat init 2019-05-21 18:14:09 +08:00
maven.publish.gradle replace code into another package and modify publish script and properties file 2019-10-08 23:17:51 +06:00
publish.gradle publish fixes 2019-10-10 14:25:01 +06:00
settings.gradle add CronDateTime related to klock 2019-10-04 23:47:20 +06:00

README.md

krontab

Download

This library was created to simplify work with from time to time things.

How to use

There are several ways to configure and use this library:

  • From some string
  • From builder

Anyway, to start some action from time to time you will need to use one of extensions/functions:

val kronScheduler = /* creating of KronScheduler instance */;

kronScheuler.doWhile {
    // some action
    true // true - repeat on next time
}

Config from string

Developers can use more simple way to configure repeat times is string. String configuring like a crontab, but with a little bit different meanings:

/-------- Seconds
| /------ Minutes
| | /---- Hours
| | | /-- Days of months
| | | | / Months
| | | | |
* * * * *

It is different with original crontab syntax for the reason, that expected that in practice developers will use seconds and minutes with more probability than months (for example). In fact, developers will use something like:

doWhile("/5 * * * *") {
    println("Called")
    true // true - repeat on next time
}

Or more version:

doInfinity("/5 * * * *") {
    println("Called")
}

Both of examples will print Called message every five seconds.

Config via builder

Also this library currently supports DSL for creating the same goals:

val kronScheduler = buildSchedule {
    seconds {
        from (0) every 5
    }
}
kronScheduler.doWhile {
    println("Called")
    true // true - repeat on next time
}

Or

val kronScheduler = buildSchedule {
    seconds {
        0 every 5
    }
}
kronScheduler.doWhile {
    println("Called")
    true // true - repeat on next time
}

Or

val kronScheduler = buildSchedule {
    seconds {
        0 every 5
    }
}
kronScheduler.doInfinity {
    println("Called")
}

All of these examples will do the same things: print Called message every five seconds.