mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2025-12-05 12:35:47 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47d84751e3 | |||
| 3aa658168d | |||
| 60458999b4 | |||
| 94573ecd43 | |||
| 241fb2ee51 | |||
| cdeea96c54 | |||
| 4b310071d7 | |||
| 5ccebc5033 | |||
| 65477bb0bc | |||
| 990b0d1011 | |||
| 5cc9c8278e | |||
| 12d2d82c71 | |||
| 0d19d80d48 | |||
| 5358bfdb47 | |||
| 5c452d58b7 | |||
| a36fd1a30a | |||
| 6dc85d7e18 |
22
CHANGELOG.md
22
CHANGELOG.md
@@ -1,5 +1,20 @@
|
||||
# Changelog
|
||||
|
||||
## 0.3.0
|
||||
|
||||
* Versions:
|
||||
* `Kotlin`: `1.3.72` -> `1.4.0`
|
||||
* `Coroutines`: `1.3.8` -> `1.3.9`
|
||||
* `Klock`: `1.11.14` -> `1.12.0`
|
||||
* Typealias `KrontabTemplate` was added
|
||||
* Extension `KrontabTemplate#toSchedule` was added
|
||||
|
||||
### 0.3.1
|
||||
|
||||
* Versions:
|
||||
* `Kotlin`: `1.4.0` -> `1.4.10`
|
||||
* `Klock`: `1.12.0` -> `1.12.1`
|
||||
|
||||
## 0.2.0
|
||||
|
||||
* Updated way of publishing (for more info look at the [git](https://git.insanusmokrassar.com/InsanusMokrassar/krontab))
|
||||
@@ -7,6 +22,13 @@
|
||||
* Coroutines `1.3.2` -> `1.3.3`
|
||||
* Klock `1.7.3` -> `1.8.6`
|
||||
|
||||
### 0.2.4
|
||||
|
||||
* Updates in libraries:
|
||||
* Klock `1.11.3` -> `1.11.14`
|
||||
* Coroutines `1.3.7` -> `1.3.8`
|
||||
* Ranges support were included. Now it is possible to correctly use syntax `0-5` in strings schedules
|
||||
|
||||
### 0.2.3
|
||||
|
||||
* Updates in libraries:
|
||||
|
||||
20
build.gradle
20
build.gradle
@@ -7,21 +7,21 @@ buildscript {
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||
id "org.jetbrains.dokka" version "$dokka_version"
|
||||
}
|
||||
|
||||
project.version = "0.2.3"
|
||||
project.version = "0.3.1"
|
||||
project.group = "com.insanusmokrassar"
|
||||
|
||||
apply from: "publish.gradle"
|
||||
apply from: "github_release.gradle"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
@@ -34,13 +34,17 @@ apply from: './dokka.gradle'
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js()
|
||||
js(BOTH) {
|
||||
browser()
|
||||
nodejs()
|
||||
}
|
||||
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
|
||||
api "com.soywiz.korlibs.klock:klock:$klockVersion"
|
||||
}
|
||||
@@ -49,24 +53,20 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
}
|
||||
}
|
||||
jsMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
||||
implementation kotlin('test-js')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
changelog_parser.sh
Normal file
24
changelog_parser.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
function parse() {
|
||||
version=$1
|
||||
|
||||
while IFS= read -r line && [ -z "`echo $line | grep -e "^#\+ $version"`" ]
|
||||
do
|
||||
: # do nothing
|
||||
done
|
||||
|
||||
while IFS= read -r line && [ -z "`echo $line | grep -e "^#\+"`" ]
|
||||
do
|
||||
echo "$line"
|
||||
done
|
||||
}
|
||||
|
||||
version=$1
|
||||
file=$2
|
||||
|
||||
if [ -n "$file" ]; then
|
||||
parse $version < "$file"
|
||||
else
|
||||
parse $version
|
||||
fi
|
||||
28
github_release.gradle
Normal file
28
github_release.gradle
Normal file
@@ -0,0 +1,28 @@
|
||||
private String getCurrentVersionChangelog() {
|
||||
OutputStream changelogDataOS = new ByteArrayOutputStream()
|
||||
exec {
|
||||
standardOutput = changelogDataOS
|
||||
commandLine 'chmod', "+x", './changelog_parser.sh'
|
||||
commandLine './changelog_parser.sh', "$library_version", 'CHANGELOG.md'
|
||||
}
|
||||
|
||||
return changelogDataOS.toString().trim()
|
||||
}
|
||||
|
||||
if (new File(projectDir, "secret.gradle").exists()) {
|
||||
apply from: './secret.gradle'
|
||||
apply plugin: "com.github.breadmoirai.github-release"
|
||||
|
||||
githubRelease {
|
||||
token "${project.property('GITHUB_RELEASE_TOKEN')}"
|
||||
|
||||
owner "InsanusMokrassar"
|
||||
repo "${rootProject.name}"
|
||||
|
||||
tagName "${project.version}"
|
||||
releaseName "${project.version}"
|
||||
targetCommitish "${project.version}"
|
||||
|
||||
body getCurrentVersionChangelog()
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
kotlin.code.style=official
|
||||
kotlin_version=1.3.72
|
||||
kotlin_coroutines_version=1.3.7
|
||||
kotlin_version=1.4.10
|
||||
kotlin_coroutines_version=1.3.9
|
||||
|
||||
dokka_version=0.10.1
|
||||
|
||||
gradle_bintray_plugin_version=1.8.4
|
||||
gradle_bintray_plugin_version=1.8.5
|
||||
|
||||
klockVersion=1.11.3
|
||||
klockVersion=1.12.1
|
||||
|
||||
github_release_plugin_version=2.2.12
|
||||
|
||||
kotlin.incremental.multiplatform=true
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
||||
# Tue May 21 17:58:54 HKT 2019
|
||||
# Fri Jul 24 23:52:00 +06 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
|
||||
|
||||
@@ -20,37 +20,33 @@ publishing {
|
||||
publications.all {
|
||||
artifact javadocsJar
|
||||
|
||||
pom.withXml {
|
||||
asNode().children().last() + {
|
||||
resolveStrategy = Closure.DELEGATE_FIRST
|
||||
pom {
|
||||
description = "It is an analog of crontab util for Kotlin Coroutines"
|
||||
name = "Krontab"
|
||||
url = "https://git.insanusmokrassar.com/InsanusMokrassar/krontab"
|
||||
|
||||
description "It is an analog of crontab util for Kotlin Coroutines"
|
||||
name "Krontab"
|
||||
url "https://git.insanusmokrassar.com/InsanusMokrassar/krontab"
|
||||
scm {
|
||||
developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com:8322/InsanusMokrassar/krontab.git[push=]https://git.insanusmokrassar.com:8322/InsanusMokrassar/krontab.git"
|
||||
url = "https://git.insanusmokrassar.com:8322/InsanusMokrassar/krontab.git"
|
||||
}
|
||||
|
||||
scm {
|
||||
developerConnection "scm:git:[fetch=]https://git.insanusmokrassar.com/InsanusMokrassar/krontab.git[push=]https://git.insanusmokrassar.com/InsanusMokrassar/krontab.git"
|
||||
url "https://git.insanusmokrassar.com/InsanusMokrassar/krontab.git"
|
||||
}
|
||||
developers {
|
||||
|
||||
developer {
|
||||
id = "InsanusMokrassar"
|
||||
name = "Ovsiannikov Aleksei"
|
||||
email = "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
developers {
|
||||
|
||||
developer {
|
||||
id "InsanusMokrassar"
|
||||
name "Ovsiannikov Aleksei"
|
||||
email "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
licenses {
|
||||
|
||||
license {
|
||||
name "Apache Software License 2.0"
|
||||
url "https://git.insanusmokrassar.com/InsanusMokrassar/krontab/src/master/LICENSE"
|
||||
}
|
||||
|
||||
}
|
||||
licenses {
|
||||
|
||||
license {
|
||||
name = "Apache Software License 2.0"
|
||||
url = "https://git.insanusmokrassar.com/InsanusMokrassar/krontab/src/master/LICENSE"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab/src/master/LICENSE"}],"mavenConfig":{"name":"Krontab","description":"It is an analog of crontab util for Kotlin Coroutines","url":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab","vcsUrl":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
|
||||
1
mpp_config.kpsb
Normal file
1
mpp_config.kpsb
Normal file
@@ -0,0 +1 @@
|
||||
{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}-mpp","packageVcs":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab/src/master/LICENSE"}],"mavenConfig":{"name":"Krontab","description":"It is an analog of crontab util for Kotlin Coroutines","url":"https://git.insanusmokrassar.com/InsanusMokrassar/krontab","vcsUrl":"https://git.insanusmokrassar.com:8322/InsanusMokrassar/krontab.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
||||
@@ -25,12 +25,15 @@ bintray {
|
||||
}
|
||||
into "${project.group}".replace(".", "/")
|
||||
}
|
||||
|
||||
publish = true
|
||||
override = true
|
||||
|
||||
pkg {
|
||||
repo = "InsanusMokrassar"
|
||||
name = "${project.name}"
|
||||
name = "${project.name}-mpp"
|
||||
vcsUrl = "https://git.insanusmokrassar.com/InsanusMokrassar/krontab"
|
||||
licenses = ["Apache-2.0"]
|
||||
override=true
|
||||
version {
|
||||
name = "${project.version}"
|
||||
released = new Date()
|
||||
|
||||
@@ -7,7 +7,7 @@ import kotlinx.coroutines.delay
|
||||
/**
|
||||
* Execute [block] once at the [KronScheduler.next] time and return result of [block] calculation.
|
||||
*
|
||||
* WARNING!!! If you want to launch it in parallel, you must do this explicit.
|
||||
* WARNING!!! If you want to launch it in parallel, you must do this explicitly.
|
||||
*/
|
||||
suspend inline fun <T> KronScheduler.doOnce(noinline block: suspend () -> T): T {
|
||||
delay((next() - DateTime.now()).millisecondsLong)
|
||||
@@ -15,12 +15,13 @@ suspend inline fun <T> KronScheduler.doOnce(noinline block: suspend () -> T): T
|
||||
}
|
||||
|
||||
/**
|
||||
* Will [createSimpleScheduler] using [scheduleConfig] and call [doOnce] on it
|
||||
* Will [buildSchedule] using [scheduleConfig] and call [doOnce] on it
|
||||
* @see buildSchedule
|
||||
*/
|
||||
suspend inline fun <T> doOnce(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend () -> T
|
||||
) = createSimpleScheduler(scheduleConfig).doOnce(block)
|
||||
) = buildSchedule(scheduleConfig).doOnce(block)
|
||||
|
||||
/**
|
||||
* Will execute [block] while it will return true as a result of its calculation
|
||||
@@ -30,12 +31,14 @@ suspend inline fun KronScheduler.doWhile(noinline block: suspend () -> Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Will [createSimpleScheduler] using [scheduleConfig] and call [doWhile] with [block]
|
||||
* Will [buildSchedule] using [scheduleConfig] and call [doWhile] with [block]
|
||||
*
|
||||
* @see buildSchedule
|
||||
*/
|
||||
suspend inline fun doWhile(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend () -> Boolean
|
||||
) = createSimpleScheduler(scheduleConfig).doWhile(block)
|
||||
) = buildSchedule(scheduleConfig).doWhile(block)
|
||||
|
||||
/**
|
||||
* Will execute [block] without any checking of result
|
||||
@@ -45,9 +48,11 @@ suspend inline fun KronScheduler.doInfinity(noinline block: suspend () -> Unit)
|
||||
true
|
||||
}
|
||||
/**
|
||||
* Will [createSimpleScheduler] using [scheduleConfig] and call [doInfinity] with [block]
|
||||
* Will [buildSchedule] using [scheduleConfig] and call [doInfinity] with [block]
|
||||
*
|
||||
* @see buildSchedule
|
||||
*/
|
||||
suspend inline fun doInfinity(
|
||||
scheduleConfig: String,
|
||||
noinline block: suspend () -> Unit
|
||||
) = createSimpleScheduler(scheduleConfig).doInfinity(block)
|
||||
) = buildSchedule(scheduleConfig).doInfinity(block)
|
||||
|
||||
@@ -2,6 +2,12 @@ package com.insanusmokrassar.krontab
|
||||
|
||||
import com.insanusmokrassar.krontab.internal.*
|
||||
|
||||
/**
|
||||
* @see createSimpleScheduler
|
||||
* @see buildSchedule
|
||||
*/
|
||||
typealias KrontabTemplate = String
|
||||
|
||||
/**
|
||||
* Parse [incoming] string and adapt according to next format: "* * * * *" where order of things:
|
||||
*
|
||||
@@ -13,7 +19,7 @@ import com.insanusmokrassar.krontab.internal.*
|
||||
*
|
||||
* And each one have next format:
|
||||
*
|
||||
* `{number},{number},...`
|
||||
* `{number}[,{number},...]` or `*`
|
||||
*
|
||||
* and {number} here is one of
|
||||
*
|
||||
@@ -38,7 +44,7 @@ import com.insanusmokrassar.krontab.internal.*
|
||||
*
|
||||
* @see com.insanusmokrassar.krontab.internal.createKronScheduler
|
||||
*/
|
||||
fun createSimpleScheduler(incoming: String): KronScheduler {
|
||||
fun createSimpleScheduler(incoming: KrontabTemplate): KronScheduler {
|
||||
val (secondsSource, minutesSource, hoursSource, dayOfMonthSource, monthSource) = incoming.split(" ")
|
||||
|
||||
val secondsParsed = parseSeconds(secondsSource)
|
||||
@@ -53,6 +59,11 @@ fun createSimpleScheduler(incoming: String): KronScheduler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Shortcut for [createSimpleScheduler]
|
||||
*/
|
||||
fun buildSchedule(incoming: String): KronScheduler = createSimpleScheduler(incoming)
|
||||
fun buildSchedule(incoming: KrontabTemplate): KronScheduler = createSimpleScheduler(incoming)
|
||||
|
||||
/**
|
||||
* Shortcut for [buildSchedule]
|
||||
*/
|
||||
fun KrontabTemplate.toSchedule(): KronScheduler = buildSchedule(this)
|
||||
@@ -81,6 +81,16 @@ sealed class TimeBuilder (
|
||||
*/
|
||||
@Suppress("unused")
|
||||
infix fun upTo(endIncluding: Int): Array<Int> = this from 0 upTo endIncluding
|
||||
/**
|
||||
* Will fill up this timeline from [this] up to [endIncluding]
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
infix operator fun Int.rangeTo(endIncluding: Int) = upTo(endIncluding)
|
||||
/**
|
||||
* Shortcut for "[from] 0 [rangeTo] [endIncluding]"
|
||||
*/
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
infix operator fun rangeTo(endIncluding: Int) = (this from 0) rangeTo endIncluding
|
||||
|
||||
internal fun build() = result ?.map { it.toByte() } ?.toTypedArray()
|
||||
}
|
||||
|
||||
@@ -28,30 +28,6 @@ internal data class CronDateTime(
|
||||
}
|
||||
|
||||
internal val klockDayOfMonth = dayOfMonth ?.plus(1)
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Using [clamp] extension for checking every parameter to be ensure that they are all correct
|
||||
* @param month 0-11
|
||||
* @param dayOfMonth 0-31
|
||||
* @param hours 0-23
|
||||
* @param minutes 0-59
|
||||
* @param seconds 0-59
|
||||
*/
|
||||
fun create(
|
||||
month: Int? = null,
|
||||
dayOfMonth: Int? = null,
|
||||
hours: Int? = null,
|
||||
minutes: Int? = null,
|
||||
seconds: Int? = null
|
||||
) = CronDateTime(
|
||||
month ?.clamp(monthRange) ?.toByte(),
|
||||
dayOfMonth ?.clamp(dayOfMonthRange) ?.toByte(),
|
||||
hours ?.clamp(hoursRange) ?.toByte(),
|
||||
minutes ?.clamp(minutesRange) ?.toByte(),
|
||||
seconds ?.clamp(secondsRange) ?.toByte()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ internal data class CronDateTimeScheduler internal constructor(
|
||||
* @see toNearDateTime
|
||||
*/
|
||||
override suspend fun next(relatively: DateTime): DateTime {
|
||||
return cronDateTimes.map { it.toNearDateTime(relatively) }.min() ?: anyCronDateTime.toNearDateTime(relatively)
|
||||
return cronDateTimes.map { it.toNearDateTime(relatively) }.minOrNull() ?: anyCronDateTime.toNearDateTime(relatively)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,10 @@ private fun createSimpleScheduler(from: String, dataRange: IntRange): Array<Byte
|
||||
|
||||
val results = things.flatMap {
|
||||
when {
|
||||
it.contains("-") -> {
|
||||
val splitted = it.split("-")
|
||||
(splitted.first().toInt().clamp(dataRange) .. splitted[1].toInt().clamp(dataRange)).toList()
|
||||
}
|
||||
it.contains("/") -> {
|
||||
val (start, step) = it.split("/")
|
||||
val startNum = (if (start.isEmpty() || start == "*") {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.insanusmokrassar.krontab.utils
|
||||
|
||||
import com.insanusmokrassar.krontab.buildSchedule
|
||||
import com.insanusmokrassar.krontab.builder.buildSchedule
|
||||
import com.insanusmokrassar.krontab.createSimpleScheduler
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -60,4 +60,23 @@ class StringParseTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySeveralSecondsRangeBuiltOnString() {
|
||||
val rangesEnds = listOf(0 to 5, 30 to 35)
|
||||
val kronScheduler = buildSchedule("${rangesEnds.joinToString(",") { "${it.first}-${it.second}" }} * * * *")
|
||||
|
||||
val flow = kronScheduler.asFlow()
|
||||
|
||||
runTest {
|
||||
val ranges = rangesEnds.map { it.first .. it.second }.flatten().toMutableList()
|
||||
val expectedCollects = rangesEnds.sumBy { it.second - it.first + 1 }
|
||||
var collected = 0
|
||||
|
||||
flow.takeWhile { ranges.isNotEmpty() }.collect {
|
||||
ranges.remove(it.seconds)
|
||||
collected++
|
||||
}
|
||||
assertEquals(expectedCollects, collected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user