mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2025-12-05 04:25:48 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1431c0cda2 | |||
| 66e75b4315 | |||
| 5a13437c17 | |||
| 6d612ce95d | |||
| 92f1ec03dd | |||
| f23740a6a5 | |||
| 16d8850ca7 | |||
| f278361470 | |||
| 47d84751e3 | |||
| 3aa658168d | |||
| 60458999b4 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -9,6 +9,22 @@
|
||||
* Typealias `KrontabTemplate` was added
|
||||
* Extension `KrontabTemplate#toSchedule` was added
|
||||
|
||||
### 0.3.2
|
||||
|
||||
* Function `TimeBuilder#each` was added (works as `at`)
|
||||
* Add opportunity to use `first` shortcuts:
|
||||
* Value property `TimeBuilder#first` for including via functions like `TimeBuilder#at`
|
||||
* Shortcut for kron string format `f` or `F`
|
||||
* Add opportunity to use `last` shortcuts:
|
||||
* Value property `TimeBuilder#last` for including via functions like `TimeBuilder#at`
|
||||
* Shortcut for kron string format `l` or `L`
|
||||
|
||||
### 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))
|
||||
|
||||
@@ -8,6 +8,7 @@ buildscript {
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version"
|
||||
classpath "com.github.breadmoirai:github-release:$github_release_plugin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,10 +17,11 @@ plugins {
|
||||
id "org.jetbrains.dokka" version "$dokka_version"
|
||||
}
|
||||
|
||||
project.version = "0.3.0"
|
||||
project.version = "0.3.2"
|
||||
project.group = "com.insanusmokrassar"
|
||||
|
||||
apply from: "publish.gradle"
|
||||
apply from: "github_release.gradle"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
||||
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
|
||||
30
github_release.gradle
Normal file
30
github_release.gradle
Normal file
@@ -0,0 +1,30 @@
|
||||
private String getCurrentVersionChangelog(String version) {
|
||||
OutputStream changelogDataOS = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'chmod', "+x", './changelog_parser.sh'
|
||||
}
|
||||
exec {
|
||||
standardOutput = changelogDataOS
|
||||
commandLine './changelog_parser.sh', "$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("${project.version}")
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
kotlin.code.style=official
|
||||
kotlin_version=1.4.0
|
||||
kotlin_version=1.4.10
|
||||
kotlin_coroutines_version=1.3.9
|
||||
|
||||
dokka_version=0.10.1
|
||||
|
||||
gradle_bintray_plugin_version=1.8.5
|
||||
|
||||
klockVersion=1.12.0
|
||||
klockVersion=1.12.1
|
||||
|
||||
github_release_plugin_version=2.2.12
|
||||
|
||||
kotlin.incremental.multiplatform=true
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}-mpp","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:8322/InsanusMokrassar/krontab.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"}
|
||||
{"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,6 +25,10 @@ bintray {
|
||||
}
|
||||
into "${project.group}".replace(".", "/")
|
||||
}
|
||||
|
||||
publish = true
|
||||
override = true
|
||||
|
||||
pkg {
|
||||
repo = "InsanusMokrassar"
|
||||
name = "${project.name}-mpp"
|
||||
|
||||
@@ -27,6 +27,8 @@ typealias KrontabTemplate = String
|
||||
* * {int}/{int}
|
||||
* * */{int}
|
||||
* * {int}
|
||||
* * F
|
||||
* * L
|
||||
*
|
||||
* Additional info about ranges can be found in follow accordance:
|
||||
*
|
||||
@@ -39,8 +41,9 @@ typealias KrontabTemplate = String
|
||||
* Examples:
|
||||
*
|
||||
* * "0/5 * * * *" for every five seconds triggering
|
||||
* * "0/5,L * * * *" for every five seconds triggering and on 59 second
|
||||
* * "0/15 30 * * *" for every 15th seconds in a half of each hour
|
||||
* * "1 2 3 4 5" for triggering in near first second of second minute of third hour of fourth day of may
|
||||
* * "1 2 3 F,4,L 5" for triggering in near first second of second minute of third hour of fourth day of may
|
||||
*
|
||||
* @see com.insanusmokrassar.krontab.internal.createKronScheduler
|
||||
*/
|
||||
|
||||
@@ -12,6 +12,17 @@ sealed class TimeBuilder (
|
||||
) {
|
||||
private var result: Set<Int>? = null
|
||||
|
||||
/**
|
||||
* The first possible value of builder
|
||||
*/
|
||||
val first
|
||||
get() = restrictionsRange.first
|
||||
/**
|
||||
* The last possible value of builder. Using of this variable equal to using "L" in strings
|
||||
*/
|
||||
val last
|
||||
get() = restrictionsRange.last
|
||||
|
||||
/**
|
||||
* After calling of this function this builder will allow any value of current time
|
||||
*/
|
||||
@@ -37,6 +48,13 @@ sealed class TimeBuilder (
|
||||
result = (result ?: emptySet()) + value.clamp(restrictionsRange)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut for [at]. In fact will
|
||||
*/
|
||||
@Suppress("unused", "NOTHING_TO_INLINE")
|
||||
inline infix fun each(value: Int) = at(value)
|
||||
|
||||
/**
|
||||
* Just wrapper for more obvious writing something like "[from] 2 [every] 5". For example, for [SecondsBuilder] it
|
||||
* will mean "[from] second second [every] 5 seconds", or "2, 7, 13, ..."
|
||||
@@ -92,6 +110,15 @@ sealed class TimeBuilder (
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
infix operator fun rangeTo(endIncluding: Int) = (this from 0) rangeTo endIncluding
|
||||
|
||||
/**
|
||||
* Will include the last possible value
|
||||
*/
|
||||
fun includeLast() = at(restrictionsRange.last)
|
||||
/**
|
||||
* Will include the first possible value
|
||||
*/
|
||||
fun includeFirst() = at(restrictionsRange.first)
|
||||
|
||||
internal fun build() = result ?.map { it.toByte() } ?.toTypedArray()
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,13 @@ internal fun CronDateTime.toNearDateTime(relativelyTo: DateTime = DateTime.now()
|
||||
}
|
||||
|
||||
klockDayOfMonth ?.let {
|
||||
val left = it - current.dayOfMonth
|
||||
val left = (it - current.dayOfMonth).let { diff ->
|
||||
if (diff > 0 && current.endOfMonth.run { it > dayOfMonth && current.dayOfMonth == dayOfMonth }) {
|
||||
0
|
||||
} else {
|
||||
diff
|
||||
}
|
||||
}
|
||||
current += DateTimeSpan(months = if (left < 0) 1 else 0, days = left)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,18 @@ private fun createSimpleScheduler(from: String, dataRange: IntRange): Array<Byte
|
||||
val things = from.split(",")
|
||||
|
||||
val results = things.flatMap {
|
||||
val currentToken = it.toLowerCase().replace(
|
||||
"f", dataRange.first.toString()
|
||||
).replace(
|
||||
"l", dataRange.last.toString()
|
||||
)
|
||||
when {
|
||||
it.contains("-") -> {
|
||||
val splitted = it.split("-")
|
||||
currentToken.contains("-") -> {
|
||||
val splitted = currentToken.split("-")
|
||||
(splitted.first().toInt().clamp(dataRange) .. splitted[1].toInt().clamp(dataRange)).toList()
|
||||
}
|
||||
it.contains("/") -> {
|
||||
val (start, step) = it.split("/")
|
||||
currentToken.contains("/") -> {
|
||||
val (start, step) = currentToken.split("/")
|
||||
val startNum = (if (start.isEmpty() || start == "*") {
|
||||
0
|
||||
} else {
|
||||
@@ -21,8 +26,8 @@ private fun createSimpleScheduler(from: String, dataRange: IntRange): Array<Byte
|
||||
val stepNum = step.toInt().clamp(dataRange)
|
||||
(startNum .. dataRange.last step stepNum).map { it }
|
||||
}
|
||||
it == "*" -> return null
|
||||
else -> listOf(it.toInt().clamp(dataRange))
|
||||
currentToken == "*" -> return null
|
||||
else -> listOf(currentToken.toInt().clamp(dataRange))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user