mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-26 12:08:50 +00:00
now base scheduling is working
This commit is contained in:
parent
eb0f78a9e4
commit
6cfb190aa8
@ -4,7 +4,6 @@ import com.github.insanusmokrassar.krontab.utils.*
|
|||||||
import com.github.insanusmokrassar.krontab.utils.clamp
|
import com.github.insanusmokrassar.krontab.utils.clamp
|
||||||
import com.github.insanusmokrassar.krontab.utils.dayOfMonthRange
|
import com.github.insanusmokrassar.krontab.utils.dayOfMonthRange
|
||||||
import com.github.insanusmokrassar.krontab.utils.monthRange
|
import com.github.insanusmokrassar.krontab.utils.monthRange
|
||||||
import com.soywiz.klock.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [month] 0-11
|
* [month] 0-11
|
||||||
@ -13,7 +12,7 @@ import com.soywiz.klock.*
|
|||||||
* [minutes] 0-59
|
* [minutes] 0-59
|
||||||
* [seconds] 0-59
|
* [seconds] 0-59
|
||||||
*/
|
*/
|
||||||
data class CronDateTime(
|
internal data class CronDateTime(
|
||||||
val month: Byte? = null,
|
val month: Byte? = null,
|
||||||
val dayOfMonth: Byte? = null,
|
val dayOfMonth: Byte? = null,
|
||||||
val hours: Byte? = null,
|
val hours: Byte? = null,
|
||||||
|
@ -8,7 +8,7 @@ private val anyCronDateTime by lazy {
|
|||||||
CronDateTime()
|
CronDateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
data class CronDateTimeScheduler(
|
internal data class CronDateTimeScheduler(
|
||||||
internal val cronDateTimes: List<CronDateTime>
|
internal val cronDateTimes: List<CronDateTime>
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ internal fun CronDateTime.toNearDateTime(relativelyTo: DateTime = DateTime.now()
|
|||||||
|
|
||||||
seconds?.let {
|
seconds?.let {
|
||||||
val left = it - current.seconds
|
val left = it - current.seconds
|
||||||
current += DateTimeSpan(minutes = if (left < 0) 1 else 0, seconds = left)
|
current += DateTimeSpan(minutes = if (left <= 0) 1 else 0, seconds = left)
|
||||||
}
|
}
|
||||||
|
|
||||||
minutes?.let {
|
minutes?.let {
|
||||||
|
@ -1,12 +1,21 @@
|
|||||||
package com.github.insanusmokrassar.krontab
|
package com.github.insanusmokrassar.krontab
|
||||||
|
|
||||||
suspend fun doWhile(scheduleConfig: String, block: suspend () -> Boolean) {
|
suspend fun executeInfinity(scheduleConfig: String, block: suspend () -> Unit) {
|
||||||
|
val scheduler = CronDateTimeScheduler(parse(scheduleConfig))
|
||||||
|
|
||||||
|
scheduler.doInLoop {
|
||||||
|
block()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun executeWhile(scheduleConfig: String, block: suspend () -> Boolean) {
|
||||||
val scheduler = CronDateTimeScheduler(parse(scheduleConfig))
|
val scheduler = CronDateTimeScheduler(parse(scheduleConfig))
|
||||||
|
|
||||||
scheduler.doInLoop(block)
|
scheduler.doInLoop(block)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun executeOnce(scheduleConfig: String, block: suspend () -> Boolean) {
|
suspend fun executeOnce(scheduleConfig: String, block: suspend () -> Unit) {
|
||||||
val scheduler = CronDateTimeScheduler(parse(scheduleConfig))
|
val scheduler = CronDateTimeScheduler(parse(scheduleConfig))
|
||||||
|
|
||||||
scheduler.doInLoop {
|
scheduler.doInLoop {
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.github.insanusmokrassar.krontab
|
||||||
|
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
runBlocking {
|
||||||
|
var i = 0
|
||||||
|
executeInfinity("/10 /25 * * *") {
|
||||||
|
println(DateTime.now())
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user