now base scheduling is working

This commit is contained in:
InsanusMokrassar 2019-10-05 11:23:48 +06:00
parent eb0f78a9e4
commit 6cfb190aa8
4 changed files with 28 additions and 6 deletions

View File

@ -4,7 +4,6 @@ import com.github.insanusmokrassar.krontab.utils.*
import com.github.insanusmokrassar.krontab.utils.clamp
import com.github.insanusmokrassar.krontab.utils.dayOfMonthRange
import com.github.insanusmokrassar.krontab.utils.monthRange
import com.soywiz.klock.*
/**
* [month] 0-11
@ -13,7 +12,7 @@ import com.soywiz.klock.*
* [minutes] 0-59
* [seconds] 0-59
*/
data class CronDateTime(
internal data class CronDateTime(
val month: Byte? = null,
val dayOfMonth: Byte? = null,
val hours: Byte? = null,

View File

@ -8,7 +8,7 @@ private val anyCronDateTime by lazy {
CronDateTime()
}
data class CronDateTimeScheduler(
internal data class CronDateTimeScheduler(
internal val cronDateTimes: List<CronDateTime>
)
@ -27,7 +27,7 @@ internal fun CronDateTime.toNearDateTime(relativelyTo: DateTime = DateTime.now()
seconds?.let {
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 {

View File

@ -1,12 +1,21 @@
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))
scheduler.doInLoop(block)
}
suspend fun executeOnce(scheduleConfig: String, block: suspend () -> Boolean) {
suspend fun executeOnce(scheduleConfig: String, block: suspend () -> Unit) {
val scheduler = CronDateTimeScheduler(parse(scheduleConfig))
scheduler.doInLoop {

View File

@ -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++
}
}
}