several fixes and krontab migration

This commit is contained in:
2023-06-10 13:39:41 +06:00
parent fe91bd17a6
commit 089d0cebac
14 changed files with 311 additions and 17 deletions

View File

@@ -0,0 +1,19 @@
# FAQ
#### How oftern new versions are releasing?
Not very often. It depend on libraries (coroutines, korlibs/klock) updates and on some new awesome, but lightweight, features coming.
#### Where this library could be useful?
First of all, this library will be useful for long uptime applications which have some tasks to do from time to time.
#### How to use crontab-like syntax?
In two words, you should call `buildSchedule` or `createSimpleScheduler`:
```kotlin
buildSchedule("5 * * * *").asFlow().collect { /* do something */ }
```
You can read more about syntax in [String format](../describing/string-format.md) section.

View File

@@ -0,0 +1,57 @@
# How to use
## Previous pages
* [Including in project](including-in-project.md)
## `buildSchedule`
> NOTE: **Custom KronScheduler**
> You always able to create your own scheduler. In this section will be presented different ways and examples around standard `CronDateTimeScheduler` builders `buildSchedule`. You can read about schedulers in [KrontabScheduler](../describing/krontabscheduler.md)
Currently, `buildSchedule` is the recommended start point for every scheduler. Usually, it is look like:
```kotlin
val scheduler = buildSchedule("5 * * * *")
```
Or:
```kotlin
val scheduler = buildSchedule {
seconds {
at(5)
}
}
```
On the top of any `KronScheduler` currently there are several groups of extensions:
* Executes
* Shortcuts
* Flows
### Executes
All executes are look like `do...`. All executes are described below:
* `doOnce` - will get the next time for executing, delay until that time and call `block` with returning of the `block` result
* `doWhile` - will call `doOnce` while it will return `true` (that means that `block` must return `true` if it expects that next call must happen). In two words: it will run while `block` returning `true`
* `doInfinity` - will call the `block` using `doWhile` with predefined returning `true`. In two words: it will call `block` while it do not throw error
### Shortcuts
Shortcuts are the constants that are initializing in a lazy way to provide preset `KronScheduler`s. For more info about `KrontabScheduler` you can read its own [page](../describing/krontabscheduler.md).
* `AnyTimeScheduler` - will always return incoming `DateTime` as next
* `Every*Scheduler` - return near * since the passed `relatively`:
* `EverySecondScheduler`
* `EveryMinuteScheduler`
* `EveryHourScheduler`
* `EveryDayOfMonthScheduler`
* `EveryMonthScheduler`
* `EveryYearScheduler`
### Flows
Here currently there is only one extension for `KronScheduler`: `KronScheduler#asFlow`. As a result you will get `Flow<DateTime>` (in fact `SchedulerFlow`) which will trigger next `emit` on each not null `next` `DateTime`

View File

@@ -0,0 +1,35 @@
# Including in project
In two words, you must add dependency `dev.inmo:krontab:$krontab_version` to your project. The latest version presented by next badge:
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/krontab/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/krontab)
### Notice about repository
To use this library, you will need to include `MavenCentral` repository in you project
###### build.gradle
```groovy
mavenCentral()
```
### Dependencies
Next snippets must be placed into your `dependencies` part of `build.gradle` (for gradle) or `pom.xml` (for maven).
#### Gradle
```groovy
implementation "dev.inmo:krontab:$krontab_version"
```
#### Maven
```xml
<dependency>
<groupId>dev.inmo</groupId>
<artifactId>krontab</artifactId>
<version>${krontab_version}</version>
</dependency>
```