This commit is contained in:
InsanusMokrassar 2019-10-05 16:34:59 +06:00
parent e465084c4c
commit cc60bfb97b
4 changed files with 34 additions and 48 deletions

View File

@ -1,18 +0,0 @@
package com.github.insanusmokrassar.krontab.utils
internal val monthNumberRegex = Regex("(1[01]?)|(\\d)")
internal val dayOfMonthNumberRegex = Regex("(30?)|([012]?\\d)")
internal val hoursNumberRegex = Regex("(2[0123]?)|([01]?\\d)")
internal val minutesOrSecondsNumberRegex = Regex("[012345]?\\d")
internal val monthRegex = Regex("[*]|((${monthNumberRegex.pattern})(,(${monthNumberRegex.pattern})){0,10})")
internal val dayOfMonthRegex = Regex("[*]|((${dayOfMonthNumberRegex.pattern})(,(${dayOfMonthNumberRegex.pattern})){0,29})")
internal val hoursRegex = Regex("[*]|((${hoursNumberRegex.pattern})(,(${hoursNumberRegex.pattern})){0,23})")
internal val minutesRegex = Regex("[*]|((${minutesOrSecondsNumberRegex.pattern})(,(${minutesOrSecondsNumberRegex.pattern})){0,59})")
internal val secondsRegex = minutesRegex
internal val monthRange = 0 .. 11
internal val dayOfMonthRange = 0 .. 30
internal val hoursRange = 0 .. 23
internal val minutesRange = 0 .. 59
internal val secondsRange = minutesRange

View File

@ -0,0 +1,27 @@
package com.github.insanusmokrassar.krontab
suspend inline fun executeWith(
scheduler: CronDateTimeScheduler,
noinline block: suspend () -> Boolean
) = scheduler.doInLoop(block)
suspend inline fun executeInfinity(
scheduleConfig: String,
noinline block: suspend () -> Unit
) = createCronDateTimeScheduler(scheduleConfig).doInLoop {
block()
true
}
suspend inline fun executeWhile(
scheduleConfig: String,
noinline block: suspend () -> Boolean
) = createCronDateTimeScheduler(scheduleConfig).doInLoop(block)
suspend inline fun executeOnce(
scheduleConfig: String,
noinline block: suspend () -> Unit
) = createCronDateTimeScheduler(scheduleConfig).doInLoop {
block()
false
}

View File

@ -0,0 +1,7 @@
package com.github.insanusmokrassar.krontab
internal val monthRange = 0 .. 11
internal val dayOfMonthRange = 0 .. 30
internal val hoursRange = 0 .. 23
internal val minutesRange = 0 .. 59
internal val secondsRange = minutesRange

View File

@ -1,30 +0,0 @@
package com.github.insanusmokrassar.krontab
suspend inline fun executeWith(
scheduler: CronDateTimeScheduler,
noinline block: suspend () -> Boolean
) = scheduler.doInLoop(block)
suspend fun executeInfinity(scheduleConfig: String, block: suspend () -> Unit) {
val scheduler = createCronDateTimeScheduler(scheduleConfig)
scheduler.doInLoop {
block()
true
}
}
suspend fun executeWhile(scheduleConfig: String, block: suspend () -> Boolean) {
val scheduler = createCronDateTimeScheduler(scheduleConfig)
scheduler.doInLoop(block)
}
suspend fun executeOnce(scheduleConfig: String, block: suspend () -> Unit) {
val scheduler = createCronDateTimeScheduler(scheduleConfig)
scheduler.doInLoop {
block()
false
}
}