This commit is contained in:
InsanusMokrassar 2020-06-03 21:07:10 +06:00
parent 237deff0e6
commit 408349be04
6 changed files with 48 additions and 8 deletions

View File

@ -12,7 +12,12 @@ dokka {
multiplatform {
global {
perPackageOption {
prefix = "com.insanusmokrassar"
skipDeprecated = true
includeNonPublic = true
reportUndocumented = true
}
sourceLink {
path = "./"
@ -21,8 +26,17 @@ dokka {
}
}
common { sourceRoot { path = "src/commonMain" } }
js { sourceRoot { path = "src/jsMain" } }
jvm { sourceRoot { path = "src/jvmMain" } }
common {
targets = ["JVM", "JS"]
sourceRoot { path = "src/commonMain" }
}
js {
targets = ["JS"]
sourceRoot { path = "src/jsMain" }
}
jvm {
targets = ["JVM"]
sourceRoot { path = "src/jvmMain" }
}
}
}

View File

@ -2,6 +2,20 @@ package com.insanusmokrassar.krontab
import com.soywiz.klock.DateTime
/**
* This interface was created for abstraction of [next] operation. Currently, there is only
* [com.insanusmokrassar.krontab.internal.CronDateTimeScheduler] realisation of this interface inside of this library,
* but you it is possible to create your own realisation of this interface for scheduling, for example, depending of
* users activity or something like this
*
* @see com.insanusmokrassar.krontab.internal.CronDateTimeScheduler
*/
interface KronScheduler {
/**
* @return Next [DateTime] when some action must be triggered according to settings of this instance
*
* @see com.insanusmokrassar.krontab.internal.CronDateTimeScheduler.next
*/
suspend fun next(relatively: DateTime = DateTime.now()): DateTime
}

View File

@ -2,6 +2,7 @@ package com.insanusmokrassar.krontab
import com.insanusmokrassar.krontab.builder.buildSchedule
import com.insanusmokrassar.krontab.internal.CronDateTime
import com.insanusmokrassar.krontab.internal.CronDateTimeScheduler
internal val anyCronDateTime by lazy {
CronDateTime()

View File

@ -1,6 +1,6 @@
package com.insanusmokrassar.krontab.builder
import com.insanusmokrassar.krontab.CronDateTimeScheduler
import com.insanusmokrassar.krontab.internal.CronDateTimeScheduler
import com.insanusmokrassar.krontab.KronScheduler
import com.insanusmokrassar.krontab.internal.CronDateTime
import com.insanusmokrassar.krontab.internal.fillWith

View File

@ -53,6 +53,9 @@ internal data class CronDateTime(
}
}
/**
* @return The near [DateTime] which happens after [relativelyTo] or will be equal to [relativelyTo]
*/
internal fun CronDateTime.toNearDateTime(relativelyTo: DateTime = DateTime.now()): DateTime {
var current = relativelyTo

View File

@ -1,12 +1,20 @@
package com.insanusmokrassar.krontab
package com.insanusmokrassar.krontab.internal
import com.insanusmokrassar.krontab.internal.CronDateTime
import com.insanusmokrassar.krontab.internal.toNearDateTime
import com.insanusmokrassar.krontab.KronScheduler
import com.insanusmokrassar.krontab.anyCronDateTime
import com.soywiz.klock.DateTime
/**
* Cron-oriented realisation of [KronScheduler]
*/
internal data class CronDateTimeScheduler internal constructor(
internal val cronDateTimes: List<CronDateTime>
) : KronScheduler {
/**
* @return Near date using [cronDateTimes] list and getting the [Iterable.min] one
*
* @see toNearDateTime
*/
override suspend fun next(relatively: DateTime): DateTime {
return cronDateTimes.map { it.toNearDateTime(relatively) }.min() ?: anyCronDateTime.toNearDateTime(relatively)
}