fill docs of SchedulerShortcuts

This commit is contained in:
InsanusMokrassar 2020-06-03 20:41:54 +06:00
parent 59cd600d60
commit 237deff0e6
2 changed files with 44 additions and 15 deletions

View File

@ -6,24 +6,44 @@ import com.insanusmokrassar.krontab.internal.CronDateTime
internal val anyCronDateTime by lazy { internal val anyCronDateTime by lazy {
CronDateTime() CronDateTime()
} }
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now]
*/
val AnyTimeScheduler: KronScheduler by lazy { val AnyTimeScheduler: KronScheduler by lazy {
CronDateTimeScheduler(listOf(anyCronDateTime)) CronDateTimeScheduler(listOf(anyCronDateTime))
} }
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one second
*/
val EverySecondScheduler: KronScheduler val EverySecondScheduler: KronScheduler
get() = AnyTimeScheduler get() = AnyTimeScheduler
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one minute
*/
val EveryMinuteScheduler: KronScheduler by lazy { val EveryMinuteScheduler: KronScheduler by lazy {
buildSchedule { minutes { 0 every 1 } } buildSchedule { minutes { 0 every 1 } }
} }
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one hour
*/
val EveryHourScheduler: KronScheduler by lazy { val EveryHourScheduler: KronScheduler by lazy {
buildSchedule { hours { 0 every 1 } } buildSchedule { hours { 0 every 1 } }
} }
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one day
*/
val EveryDayOfMonthScheduler: KronScheduler by lazy { val EveryDayOfMonthScheduler: KronScheduler by lazy {
buildSchedule { dayOfMonth { 0 every 1 } } buildSchedule { dayOfMonth { 0 every 1 } }
} }
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one month
*/
val EveryMonthScheduler: KronScheduler by lazy { val EveryMonthScheduler: KronScheduler by lazy {
buildSchedule { months { 0 every 1 } } buildSchedule { months { 0 every 1 } }
} }

View File

@ -5,27 +5,36 @@ import com.insanusmokrassar.krontab.internal.*
/** /**
* Parse [incoming] string and adapt according to next format: "* * * * *" where order of things: * Parse [incoming] string and adapt according to next format: "* * * * *" where order of things:
* *
* seconds * * seconds
* minutes * * minutes
* hours * * hours
* dayOfMonth * * dayOfMonth
* month * * month
* *
* And each one have next format: * And each one have next format:
* *
* {number},{number},... * `{number},{number},...`
* *
* and {number} here is one of {int}-{int} OR {int}/{int} OR *\/{int} OR {int}. * and {number} here is one of
* *
* Seconds ranges can be found in [com.insanusmokrassar.krontab.internal.secondsRange]. * * {int}-{int}
* Minutes ranges can be found in [com.insanusmokrassar.krontab.internal.minutesRange]. * * {int}/{int}
* Hours ranges can be found in [com.insanusmokrassar.krontab.internal.hoursRange]. * * */{int}
* Days of month ranges can be found in [com.insanusmokrassar.krontab.internal.dayOfMonthRange]. * * {int}
* Months ranges can be found in [com.insanusmokrassar.krontab.internal.monthRange].
* *
* @sample "0/5 * * * *" for every five seconds triggering * Additional info about ranges can be found in follow accordance:
* @sample "0/15 30 * * *" for every 15th seconds in a half of each hour *
* @sample "1 2 3 4 5" for triggering in near first second of second minute of third hour of fourth day of may * * Seconds ranges can be found in [secondsRange]
* * Minutes ranges can be found in [minutesRange]
* * Hours ranges can be found in [hoursRange]
* * Days of month ranges can be found in [dayOfMonthRange]
* * Months ranges can be found in [monthRange]
*
* Examples:
*
* * "0/5 * * * *" for every five seconds triggering
* * "0/15 30 * * *" for every 15th seconds in a half of each hour
* * "1 2 3 4 5" for triggering in near first second of second minute of third hour of fourth day of may
*/ */
fun createSimpleScheduler(incoming: String): KronScheduler { fun createSimpleScheduler(incoming: String): KronScheduler {
val (secondsSource, minutesSource, hoursSource, dayOfMonthSource, monthSource) = incoming.split(" ") val (secondsSource, minutesSource, hoursSource, dayOfMonthSource, monthSource) = incoming.split(" ")