mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2026-04-13 19:52:33 +00:00
Compare commits
6 Commits
v2.6.0
...
33366ac2a8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33366ac2a8 | ||
| 4afebd8b7e | |||
| c76ca1798e | |||
| 58917c6458 | |||
| 5ef6134d9f | |||
|
|
e5b33ae9b0 |
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.6.1
|
||||||
|
|
||||||
|
* Fixes in parsing of string parts
|
||||||
|
|
||||||
## 2.6.0
|
## 2.6.0
|
||||||
|
|
||||||
* Fix of `doOnceTz` behaviour: now it will use local time as utc time to get next waking up time
|
* Fix of `doOnceTz` behaviour: now it will use local time as utc time to get next waking up time
|
||||||
|
|||||||
@@ -36,5 +36,5 @@ androidx_work_version=2.10.0
|
|||||||
|
|
||||||
## Common
|
## Common
|
||||||
|
|
||||||
version=2.6.0
|
version=2.6.1
|
||||||
android_code_version=44
|
android_code_version=45
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlin.coroutines.coroutineContext
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
|
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
|
||||||
*
|
*
|
||||||
@@ -55,7 +54,7 @@ suspend inline fun <T> KronScheduler.doOnceTz(noinline block: suspend (DateTimeT
|
|||||||
* @see buildSchedule
|
* @see buildSchedule
|
||||||
*/
|
*/
|
||||||
suspend inline fun <T> doOnce(
|
suspend inline fun <T> doOnce(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
block: (DateTime) -> T
|
block: (DateTime) -> T
|
||||||
) = buildSchedule(scheduleConfig).doOnce(block)
|
) = buildSchedule(scheduleConfig).doOnce(block)
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ suspend inline fun <T> doOnce(
|
|||||||
* @see buildSchedule
|
* @see buildSchedule
|
||||||
*/
|
*/
|
||||||
suspend inline fun <T> doOnceTz(
|
suspend inline fun <T> doOnceTz(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
noinline block: suspend (DateTimeTz) -> T
|
noinline block: suspend (DateTimeTz) -> T
|
||||||
) = buildSchedule(scheduleConfig).doOnceTz(block)
|
) = buildSchedule(scheduleConfig).doOnceTz(block)
|
||||||
|
|
||||||
@@ -116,7 +115,7 @@ suspend inline fun KronScheduler.doWhileTz(noinline block: suspend (DateTimeTz)
|
|||||||
* @see buildSchedule
|
* @see buildSchedule
|
||||||
*/
|
*/
|
||||||
suspend inline fun doWhile(
|
suspend inline fun doWhile(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
block: (DateTime) -> Boolean
|
block: (DateTime) -> Boolean
|
||||||
) = buildSchedule(scheduleConfig).doWhile(block)
|
) = buildSchedule(scheduleConfig).doWhile(block)
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ suspend inline fun doWhile(
|
|||||||
*/
|
*/
|
||||||
@Deprecated("Replaceable", ReplaceWith("doWhile", "dev.inmo.krontab.doWhile"))
|
@Deprecated("Replaceable", ReplaceWith("doWhile", "dev.inmo.krontab.doWhile"))
|
||||||
suspend inline fun doWhileLocal(
|
suspend inline fun doWhileLocal(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
block: (DateTime) -> Boolean
|
block: (DateTime) -> Boolean
|
||||||
) = doWhile(scheduleConfig, block)
|
) = doWhile(scheduleConfig, block)
|
||||||
|
|
||||||
@@ -137,7 +136,7 @@ suspend inline fun doWhileLocal(
|
|||||||
* @see buildSchedule
|
* @see buildSchedule
|
||||||
*/
|
*/
|
||||||
suspend inline fun doWhileTz(
|
suspend inline fun doWhileTz(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
noinline block: suspend (DateTimeTz) -> Boolean
|
noinline block: suspend (DateTimeTz) -> Boolean
|
||||||
) = buildSchedule(scheduleConfig).doWhileTz(block)
|
) = buildSchedule(scheduleConfig).doWhileTz(block)
|
||||||
|
|
||||||
@@ -169,7 +168,7 @@ suspend inline fun KronScheduler.doInfinityTz(noinline block: suspend (DateTimeT
|
|||||||
* @see buildSchedule
|
* @see buildSchedule
|
||||||
*/
|
*/
|
||||||
suspend inline fun doInfinity(
|
suspend inline fun doInfinity(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
block: (DateTime) -> Unit
|
block: (DateTime) -> Unit
|
||||||
) = buildSchedule(scheduleConfig).doInfinity(block)
|
) = buildSchedule(scheduleConfig).doInfinity(block)
|
||||||
|
|
||||||
@@ -180,7 +179,7 @@ suspend inline fun doInfinity(
|
|||||||
*/
|
*/
|
||||||
@Deprecated("Replaceable", ReplaceWith("doInfinity", "dev.inmo.krontab.doInfinity"))
|
@Deprecated("Replaceable", ReplaceWith("doInfinity", "dev.inmo.krontab.doInfinity"))
|
||||||
suspend inline fun doInfinityLocal(
|
suspend inline fun doInfinityLocal(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
block: (DateTime) -> Unit
|
block: (DateTime) -> Unit
|
||||||
) = doInfinity(scheduleConfig, block)
|
) = doInfinity(scheduleConfig, block)
|
||||||
|
|
||||||
@@ -190,6 +189,6 @@ suspend inline fun doInfinityLocal(
|
|||||||
* @see buildSchedule
|
* @see buildSchedule
|
||||||
*/
|
*/
|
||||||
suspend inline fun doInfinityTz(
|
suspend inline fun doInfinityTz(
|
||||||
scheduleConfig: String,
|
@Language("CronExp") scheduleConfig: String,
|
||||||
noinline block: suspend (DateTimeTz) -> Unit
|
noinline block: suspend (DateTimeTz) -> Unit
|
||||||
) = buildSchedule(scheduleConfig).doInfinityTz(block)
|
) = buildSchedule(scheduleConfig).doInfinityTz(block)
|
||||||
|
|||||||
6
src/commonMain/kotlin/Language.kt
Normal file
6
src/commonMain/kotlin/Language.kt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package dev.inmo.krontab
|
||||||
|
|
||||||
|
import kotlin.OptionalExpectation
|
||||||
|
|
||||||
|
@OptionalExpectation
|
||||||
|
internal expect annotation class Language(val value: String, val prefix: String = "", val suffix: String = "")
|
||||||
@@ -41,53 +41,80 @@ private fun <T> createSimpleScheduler(from: String, dataRange: IntRange, dataCon
|
|||||||
* FSM for parsing of incoming data. If at the end of parsing it have non-null state and string is not empty, data passed check
|
* FSM for parsing of incoming data. If at the end of parsing it have non-null state and string is not empty, data passed check
|
||||||
*
|
*
|
||||||
* 1.
|
* 1.
|
||||||
* * \\d -> 1
|
* * "\\d" -> 2
|
||||||
* * \\* -> 2
|
* * "\\*" -> 4
|
||||||
* * \\- -> 5
|
* * "f" -> 7
|
||||||
* * , -> 1
|
* * "l" -> 7
|
||||||
* * m -> 6
|
* * "/" -> 6
|
||||||
* * o -> 7
|
|
||||||
* * w -> 7
|
|
||||||
* 2.
|
* 2.
|
||||||
* * / -> 3
|
* * "\\d" -> 2
|
||||||
|
* * "/" -> 6
|
||||||
|
* * "," -> 1
|
||||||
|
* * "-" -> 3
|
||||||
|
* * "m" -> 9
|
||||||
|
* * "o" -> 10
|
||||||
|
* * "w" -> 10
|
||||||
* 3.
|
* 3.
|
||||||
* * \\d -> 3
|
* * "l" -> 7
|
||||||
* * \\* -> 4
|
* * "\\d" -> 8
|
||||||
* 4.
|
* 4.
|
||||||
* * , -> 1
|
* * "/" -> 6
|
||||||
|
* * "," -> 1
|
||||||
* 5.
|
* 5.
|
||||||
* * \\d -> 5
|
* * "/" -> 6
|
||||||
* * , -> 1
|
|
||||||
* 6.
|
* 6.
|
||||||
* * s -> 7
|
* * "\\d" -> 8
|
||||||
* 7. Empty, end of parse
|
* * "\\*" -> 7
|
||||||
|
* 7.
|
||||||
|
* * "," -> 1
|
||||||
|
* 8.
|
||||||
|
* * "\\d" -> 8
|
||||||
|
* * "," -> 1
|
||||||
|
* 9.
|
||||||
|
* * "s" -> 10 // end of ms
|
||||||
|
* 10. Empty, end of parse
|
||||||
*/
|
*/
|
||||||
private val checkIncomingPartTransitionsMap = listOf(
|
private val checkIncomingPartTransitionsMap = listOf(
|
||||||
listOf(
|
listOf( // 0
|
||||||
Regex("\\d") to 0,
|
Regex("\\d") to 1,
|
||||||
Regex("\\*") to 1,
|
|
||||||
Regex("-") to 4,
|
|
||||||
Regex(",") to 0,
|
|
||||||
Regex("m") to 5,
|
|
||||||
Regex("o") to 6,
|
|
||||||
Regex("w") to 6,
|
|
||||||
),
|
|
||||||
listOf(
|
|
||||||
Regex("/") to 2,
|
|
||||||
),
|
|
||||||
listOf(
|
|
||||||
Regex("\\d") to 2,
|
|
||||||
Regex("\\*") to 3,
|
Regex("\\*") to 3,
|
||||||
|
Regex("f") to 6,
|
||||||
|
Regex("l") to 6,
|
||||||
|
Regex("/") to 5,
|
||||||
),
|
),
|
||||||
listOf(
|
listOf( // 1
|
||||||
|
Regex("\\d") to 1,
|
||||||
|
Regex("/") to 5,
|
||||||
|
Regex(",") to 0,
|
||||||
|
Regex("-") to 2,
|
||||||
|
Regex("m") to 8,
|
||||||
|
Regex("o") to 9,
|
||||||
|
Regex("w") to 9,
|
||||||
|
),
|
||||||
|
listOf( // 2
|
||||||
|
Regex("l") to 6,
|
||||||
|
Regex("\\d") to 7,
|
||||||
|
),
|
||||||
|
listOf( // 3
|
||||||
|
Regex("/") to 5,
|
||||||
Regex(",") to 0,
|
Regex(",") to 0,
|
||||||
),
|
),
|
||||||
listOf(
|
listOf( // 4
|
||||||
Regex("\\d") to 4,
|
Regex("/") to 5,
|
||||||
|
),
|
||||||
|
listOf( // 5
|
||||||
|
Regex("\\d") to 7,
|
||||||
|
Regex("\\*") to 6,
|
||||||
|
),
|
||||||
|
listOf( // 6
|
||||||
Regex(",") to 0,
|
Regex(",") to 0,
|
||||||
),
|
),
|
||||||
listOf(
|
listOf( // 7
|
||||||
Regex("s") to 6, // end of ms
|
Regex("\\d") to 7,
|
||||||
|
Regex(",") to 0,
|
||||||
|
),
|
||||||
|
listOf( // 8
|
||||||
|
Regex("s") to 9, // end of ms
|
||||||
),
|
),
|
||||||
listOf(), // empty state, end of parsing
|
listOf(), // empty state, end of parsing
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dev.inmo.krontab.utils
|
|||||||
|
|
||||||
import korlibs.time.*
|
import korlibs.time.*
|
||||||
import dev.inmo.krontab.KronSchedulerTz
|
import dev.inmo.krontab.KronSchedulerTz
|
||||||
|
import dev.inmo.krontab.KrontabTemplate
|
||||||
import dev.inmo.krontab.buildSchedule
|
import dev.inmo.krontab.buildSchedule
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.takeWhile
|
import kotlinx.coroutines.flow.takeWhile
|
||||||
@@ -11,73 +12,51 @@ import kotlin.test.*
|
|||||||
@ExperimentalCoroutinesApi
|
@ExperimentalCoroutinesApi
|
||||||
@FlowPreview
|
@FlowPreview
|
||||||
class StringParseTest {
|
class StringParseTest {
|
||||||
@Test
|
private fun makeSimpleEverySecondTest(template: KrontabTemplate) {
|
||||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
val kronScheduler = buildSchedule(template)
|
||||||
val kronScheduler = buildSchedule("*/1 * * * *")
|
|
||||||
|
|
||||||
val flow = kronScheduler.asFlowWithoutDelays()
|
val flow = kronScheduler.asFlowWithoutDelays()
|
||||||
|
|
||||||
runTest {
|
runTest {
|
||||||
val mustBeCollected = 10
|
val mustBeCollected = 10
|
||||||
var collected = 0
|
var collected = 0
|
||||||
|
var previousTime: DateTime? = null
|
||||||
flow.takeWhile {
|
flow.takeWhile {
|
||||||
collected < mustBeCollected
|
collected < mustBeCollected
|
||||||
}.collect {
|
}.collect {
|
||||||
|
previousTime ?.let { previousTime ->
|
||||||
|
assertEquals(previousTime + 1.seconds, it)
|
||||||
|
}
|
||||||
|
previousTime = it
|
||||||
collected++
|
collected++
|
||||||
}
|
}
|
||||||
assertEquals(mustBeCollected, collected)
|
assertEquals(mustBeCollected, collected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
||||||
|
makeSimpleEverySecondTest("*/1 * * * *")
|
||||||
|
}
|
||||||
@Test
|
@Test
|
||||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithWrongAmountOfSpaces() {
|
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithWrongAmountOfSpaces() {
|
||||||
val kronScheduler = buildSchedule("*/1 * * * * ")
|
val templatesFirstReplacers = listOf(
|
||||||
|
"*/1",
|
||||||
val flow = kronScheduler.asFlowWithoutDelays()
|
"*",
|
||||||
|
"/1",
|
||||||
runTest {
|
"f,/1",
|
||||||
val mustBeCollected = 10
|
)
|
||||||
var collected = 0
|
templatesFirstReplacers.forEach { replacer ->
|
||||||
flow.takeWhile {
|
makeSimpleEverySecondTest("$replacer * * * * ")
|
||||||
collected < mustBeCollected
|
|
||||||
}.collect {
|
|
||||||
collected++
|
|
||||||
}
|
|
||||||
assertEquals(mustBeCollected, collected)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithGarbageInTemplate() {
|
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithGarbageInTemplate() {
|
||||||
val kronScheduler = buildSchedule(" sdf */1 * * * oo * ")
|
makeSimpleEverySecondTest(" sdf */1 * * * oo * ")
|
||||||
|
|
||||||
val flow = kronScheduler.asFlowWithoutDelays()
|
|
||||||
|
|
||||||
runTest {
|
|
||||||
val mustBeCollected = 10
|
|
||||||
var collected = 0
|
|
||||||
flow.takeWhile {
|
|
||||||
collected < mustBeCollected
|
|
||||||
}.collect {
|
|
||||||
collected++
|
|
||||||
}
|
|
||||||
assertEquals(mustBeCollected, collected)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithInsufficientArgsInTemplate() {
|
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithInsufficientArgsInTemplate() {
|
||||||
val kronScheduler = buildSchedule(" sdf */1 ")
|
makeSimpleEverySecondTest(" sdf */1 ")
|
||||||
|
|
||||||
val flow = kronScheduler.asFlowWithoutDelays()
|
|
||||||
|
|
||||||
runTest {
|
|
||||||
val mustBeCollected = 10
|
|
||||||
var collected = 0
|
|
||||||
flow.takeWhile {
|
|
||||||
collected < mustBeCollected
|
|
||||||
}.collect {
|
|
||||||
collected++
|
|
||||||
}
|
|
||||||
assertEquals(mustBeCollected, collected)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun testThatFlowIsCorrectlyWorkEverySecondWhenMillisIsHalfOfSecondBuiltOnString() {
|
fun testThatFlowIsCorrectlyWorkEverySecondWhenMillisIsHalfOfSecondBuiltOnString() {
|
||||||
@@ -88,9 +67,14 @@ class StringParseTest {
|
|||||||
runTest {
|
runTest {
|
||||||
val mustBeCollected = 10
|
val mustBeCollected = 10
|
||||||
var collected = 0
|
var collected = 0
|
||||||
|
var previousTime: DateTime? = null
|
||||||
flow.takeWhile {
|
flow.takeWhile {
|
||||||
collected < mustBeCollected
|
collected < mustBeCollected
|
||||||
}.collect {
|
}.collect {
|
||||||
|
previousTime ?.let { previousTime ->
|
||||||
|
assertEquals(previousTime.copy(milliseconds = 500) + 1.seconds, it)
|
||||||
|
}
|
||||||
|
previousTime = it
|
||||||
collected++
|
collected++
|
||||||
}
|
}
|
||||||
assertEquals(mustBeCollected, collected)
|
assertEquals(mustBeCollected, collected)
|
||||||
|
|||||||
5
src/jvmMain/kotlin/Language.kt
Normal file
5
src/jvmMain/kotlin/Language.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.krontab
|
||||||
|
|
||||||
|
import org.intellij.lang.annotations.Language
|
||||||
|
|
||||||
|
actual typealias Language = Language
|
||||||
Reference in New Issue
Block a user