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 {
CronDateTime()
}
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now]
*/
val AnyTimeScheduler: KronScheduler by lazy {
CronDateTimeScheduler(listOf(anyCronDateTime))
}
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one second
*/
val EverySecondScheduler: KronScheduler
get() = AnyTimeScheduler
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one minute
*/
val EveryMinuteScheduler: KronScheduler by lazy {
buildSchedule { minutes { 0 every 1 } }
}
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one hour
*/
val EveryHourScheduler: KronScheduler by lazy {
buildSchedule { hours { 0 every 1 } }
}
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one day
*/
val EveryDayOfMonthScheduler: KronScheduler by lazy {
buildSchedule { dayOfMonth { 0 every 1 } }
}
/**
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one month
*/
val EveryMonthScheduler: KronScheduler by lazy {
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:
*
* seconds
* minutes
* hours
* dayOfMonth
* month
* * seconds
* * minutes
* * hours
* * dayOfMonth
* * month
*
* 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].
* Minutes ranges can be found in [com.insanusmokrassar.krontab.internal.minutesRange].
* Hours ranges can be found in [com.insanusmokrassar.krontab.internal.hoursRange].
* Days of month ranges can be found in [com.insanusmokrassar.krontab.internal.dayOfMonthRange].
* Months ranges can be found in [com.insanusmokrassar.krontab.internal.monthRange].
* * {int}-{int}
* * {int}/{int}
* * */{int}
* * {int}
*
* @sample "0/5 * * * *" for every five seconds triggering
* @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
* Additional info about ranges can be found in follow accordance:
*
* * 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 {
val (secondsSource, minutesSource, hoursSource, dayOfMonthSource, monthSource) = incoming.split(" ")