mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-24 19:18:50 +00:00
Compare commits
1 Commits
7aa60e73f1
...
774d9ecada
Author | SHA1 | Date | |
---|---|---|---|
|
774d9ecada |
5
.github/workflows/publishing_packages.yml
vendored
5
.github/workflows/publishing_packages.yml
vendored
@ -14,6 +14,11 @@ jobs:
|
||||
sed -i -e "s/^version=\([0-9\.]*\)/version=\1-branch_$branch-build${{ github.run_number }}/" gradle.properties
|
||||
- name: prebuild
|
||||
run: ./gradlew clean build
|
||||
- name: Publish to Gitea
|
||||
continue-on-error: true
|
||||
run: ./gradlew publishAllPublicationsToGiteaRepository
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
- name: Publish package
|
||||
continue-on-error: true
|
||||
run: ./gradlew --no-parallel publishAllPublicationsToGithubPackagesRepository
|
||||
|
16
CHANGELOG.md
16
CHANGELOG.md
@ -1,21 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 2.6.1
|
||||
|
||||
* Fixes in parsing of string parts
|
||||
|
||||
## 2.6.0
|
||||
|
||||
* Fix of `doOnceTz` behaviour: now it will use local time as utc time to get next waking up time
|
||||
|
||||
## 2.5.1
|
||||
|
||||
* Add cleaning up of incoming template, which must remove all malformed parts from string template (fix of [#126](https://github.com/InsanusMokrassar/krontab/issues/126))
|
||||
* Add support of insufficient amount of arguments (fix of [#126](https://github.com/InsanusMokrassar/krontab/issues/126))
|
||||
* `Version`:
|
||||
* `Kotlin`: `2.0.21`
|
||||
* `AndroidXWork`: `2.10.0`
|
||||
|
||||
## 2.5.0
|
||||
|
||||
* `Version`:
|
||||
|
@ -9,7 +9,7 @@ android.useAndroidX=true
|
||||
android.enableJetifier=false
|
||||
|
||||
|
||||
kotlin_version=2.0.21
|
||||
kotlin_version=2.0.20
|
||||
kotlin_coroutines_version=1.9.0
|
||||
kotlin_serialization_version=1.7.3
|
||||
|
||||
@ -32,9 +32,9 @@ junit_version=4.12
|
||||
test_ext_junit_version=1.1.3
|
||||
espresso_core=3.4.0
|
||||
|
||||
androidx_work_version=2.10.0
|
||||
androidx_work_version=2.9.1
|
||||
|
||||
## Common
|
||||
|
||||
version=2.6.1
|
||||
android_code_version=45
|
||||
version=2.5.0
|
||||
android_code_version=42
|
||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
||||
|
@ -35,8 +35,6 @@ suspend inline fun <T> KronScheduler.doOnceLocal(block: (DateTime) -> T): T = do
|
||||
/**
|
||||
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
|
||||
*
|
||||
* WARNING!!! This method will use local time instead of utc
|
||||
*
|
||||
* WARNING!!! If you want to launch it in parallel, you must do this explicitly.
|
||||
*
|
||||
* WARNING!!! In case if [KronScheduler.next] of [this] instance will return null, [block] will be called immediatelly
|
||||
@ -44,7 +42,7 @@ suspend inline fun <T> KronScheduler.doOnceLocal(block: (DateTime) -> T): T = do
|
||||
suspend inline fun <T> KronScheduler.doOnceTz(noinline block: suspend (DateTimeTz) -> T): T {
|
||||
val time = when (this) {
|
||||
is KronSchedulerTz -> nextOrNowWithOffset()
|
||||
else -> nextTimeZoned() ?: DateTimeTz.nowLocal()
|
||||
else -> nextOrNow().local
|
||||
}
|
||||
delay((time - DateTimeTz.nowLocal()).millisecondsLong)
|
||||
return block(time)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package dev.inmo.krontab
|
||||
|
||||
import dev.inmo.krontab.internal.*
|
||||
import dev.inmo.krontab.internal.CronDateTimeScheduler
|
||||
import dev.inmo.krontab.internal.CronDateTimeSchedulerTz
|
||||
import dev.inmo.krontab.internal.createKronScheduler
|
||||
@ -95,17 +94,7 @@ value class KrontabConfig(
|
||||
var dayOfWeekParsed: Array<Byte>? = null
|
||||
var yearParsed: Array<Int>? = null
|
||||
var millisecondsParsed: Array<Short>? = null
|
||||
val (secondsSource, minutesSource, hoursSource, dayOfMonthSource, monthSource) = template
|
||||
.split(" ")
|
||||
.filter { checkIncomingPart(it) } // filter garbage from string
|
||||
.let {
|
||||
if (it.size < 5) { // reconstruction in case of insufficient arguments; 5 is amount of required arguments out of latest also code
|
||||
it + (it.size until 5).map { "*" }
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
.also {
|
||||
val (secondsSource, minutesSource, hoursSource, dayOfMonthSource, monthSource) = template.split(" ").also {
|
||||
listOfNotNull(
|
||||
it.getOrNull(5),
|
||||
it.getOrNull(6),
|
||||
|
@ -37,103 +37,6 @@ private fun <T> createSimpleScheduler(from: String, dataRange: IntRange, dataCon
|
||||
return results.map(dataConverter)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* * "\\d" -> 2
|
||||
* * "\\*" -> 4
|
||||
* * "f" -> 7
|
||||
* * "l" -> 7
|
||||
* * "/" -> 6
|
||||
* 2.
|
||||
* * "\\d" -> 2
|
||||
* * "/" -> 6
|
||||
* * "," -> 1
|
||||
* * "-" -> 3
|
||||
* * "m" -> 9
|
||||
* * "o" -> 10
|
||||
* * "w" -> 10
|
||||
* 3.
|
||||
* * "l" -> 7
|
||||
* * "\\d" -> 8
|
||||
* 4.
|
||||
* * "/" -> 6
|
||||
* * "," -> 1
|
||||
* 5.
|
||||
* * "/" -> 6
|
||||
* 6.
|
||||
* * "\\d" -> 8
|
||||
* * "\\*" -> 7
|
||||
* 7.
|
||||
* * "," -> 1
|
||||
* 8.
|
||||
* * "\\d" -> 8
|
||||
* * "," -> 1
|
||||
* 9.
|
||||
* * "s" -> 10 // end of ms
|
||||
* 10. Empty, end of parse
|
||||
*/
|
||||
private val checkIncomingPartTransitionsMap = listOf(
|
||||
listOf( // 0
|
||||
Regex("\\d") to 1,
|
||||
Regex("\\*") to 3,
|
||||
Regex("f") to 6,
|
||||
Regex("l") to 6,
|
||||
Regex("/") to 5,
|
||||
),
|
||||
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,
|
||||
),
|
||||
listOf( // 4
|
||||
Regex("/") to 5,
|
||||
),
|
||||
listOf( // 5
|
||||
Regex("\\d") to 7,
|
||||
Regex("\\*") to 6,
|
||||
),
|
||||
listOf( // 6
|
||||
Regex(",") to 0,
|
||||
),
|
||||
listOf( // 7
|
||||
Regex("\\d") to 7,
|
||||
Regex(",") to 0,
|
||||
),
|
||||
listOf( // 8
|
||||
Regex("s") to 9, // end of ms
|
||||
),
|
||||
listOf(), // empty state, end of parsing
|
||||
)
|
||||
internal fun checkIncomingPart(part: String): Boolean {
|
||||
var i = 0
|
||||
var state = checkIncomingPartTransitionsMap[0]
|
||||
while (i < part.length) {
|
||||
val char = part[i]
|
||||
val nextState = state.firstNotNullOfOrNull {
|
||||
it.second.takeIf { _ -> it.first.matches("$char") }
|
||||
}
|
||||
if (nextState == null) return false
|
||||
state = checkIncomingPartTransitionsMap[nextState]
|
||||
i++
|
||||
}
|
||||
|
||||
return part.isNotEmpty()
|
||||
}
|
||||
|
||||
internal fun parseWeekDay(from: String?) = from ?.let { if (it.endsWith("w")) createSimpleScheduler(it.removeSuffix("w"), dayOfWeekRange, intToByteConverter) ?.toTypedArray() else null }
|
||||
internal fun parseOffset(from: String?) = from ?.let { if (it.endsWith("o")) it.removeSuffix("o").toIntOrNull() else null }
|
||||
internal fun parseYears(from: String?) = from ?.let { createSimpleScheduler(from, yearRange, intToIntConverter) ?.toTypedArray() }
|
||||
|
@ -2,7 +2,6 @@ package dev.inmo.krontab.utils
|
||||
|
||||
import korlibs.time.*
|
||||
import dev.inmo.krontab.KronSchedulerTz
|
||||
import dev.inmo.krontab.KrontabTemplate
|
||||
import dev.inmo.krontab.buildSchedule
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
@ -12,52 +11,23 @@ import kotlin.test.*
|
||||
@ExperimentalCoroutinesApi
|
||||
@FlowPreview
|
||||
class StringParseTest {
|
||||
private fun makeSimpleEverySecondTest(template: KrontabTemplate) {
|
||||
val kronScheduler = buildSchedule(template)
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
||||
val kronScheduler = buildSchedule("*/1 * * * *")
|
||||
|
||||
val flow = kronScheduler.asFlowWithoutDelays()
|
||||
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
var previousTime: DateTime? = null
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
previousTime ?.let { previousTime ->
|
||||
assertEquals(previousTime + 1.seconds, it)
|
||||
}
|
||||
previousTime = it
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
||||
makeSimpleEverySecondTest("*/1 * * * *")
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithWrongAmountOfSpaces() {
|
||||
val templatesFirstReplacers = listOf(
|
||||
"*/1",
|
||||
"*",
|
||||
"/1",
|
||||
"f,/1",
|
||||
)
|
||||
templatesFirstReplacers.forEach { replacer ->
|
||||
makeSimpleEverySecondTest("$replacer * * * * ")
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithGarbageInTemplate() {
|
||||
makeSimpleEverySecondTest(" sdf */1 * * * oo * ")
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithInsufficientArgsInTemplate() {
|
||||
makeSimpleEverySecondTest(" sdf */1 ")
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondWhenMillisIsHalfOfSecondBuiltOnString() {
|
||||
val kronScheduler = buildSchedule("*/1 * * * * 500ms")
|
||||
@ -67,14 +37,9 @@ class StringParseTest {
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
var previousTime: DateTime? = null
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
previousTime ?.let { previousTime ->
|
||||
assertEquals(previousTime.copy(milliseconds = 500) + 1.seconds, it)
|
||||
}
|
||||
previousTime = it
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
|
Loading…
Reference in New Issue
Block a user