{"id":17335777,"url":"https://github.com/insanusmokrassar/krontab","last_synced_at":"2025-04-05T10:08:00.868Z","repository":{"id":37866098,"uuid":"222693433","full_name":"InsanusMokrassar/krontab","owner":"InsanusMokrassar","description":"Library for using Crontab-like syntax in scheduling of some Kotlin Coroutines tasks to do from time to time","archived":false,"fork":false,"pushed_at":"2025-03-24T19:09:37.000Z","size":1856,"stargazers_count":113,"open_issues_count":8,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T09:08:47.004Z","etag":null,"topics":["crontab-format","kotlin","kotlin-android","kotlin-coroutine-flow","kotlin-coroutines","kotlin-js","kotlin-jvm","kotlin-library","kotlin-multiplatform","scheduling"],"latest_commit_sha":null,"homepage":"https://docs.inmo.dev/krontab/index.html","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InsanusMokrassar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"patreon":"InsanusMokrassar","custom":["https://paypal.me/InsanusMokrassar?locale.x=ru_RU"]}},"created_at":"2019-11-19T12:41:14.000Z","updated_at":"2025-03-07T10:11:09.000Z","dependencies_parsed_at":"2023-01-29T01:45:57.655Z","dependency_job_id":"c0074649-8c04-4bb8-ab22-a0f833acb8c1","html_url":"https://github.com/InsanusMokrassar/krontab","commit_stats":null,"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InsanusMokrassar%2Fkrontab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InsanusMokrassar%2Fkrontab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InsanusMokrassar%2Fkrontab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InsanusMokrassar%2Fkrontab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InsanusMokrassar","download_url":"https://codeload.github.com/InsanusMokrassar/krontab/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247318744,"owners_count":20919484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crontab-format","kotlin","kotlin-android","kotlin-coroutine-flow","kotlin-coroutines","kotlin-js","kotlin-jvm","kotlin-library","kotlin-multiplatform","scheduling"],"created_at":"2024-10-15T15:12:12.263Z","updated_at":"2025-04-05T10:08:00.836Z","avatar_url":"https://github.com/InsanusMokrassar.png","language":"Kotlin","funding_links":["https://patreon.com/InsanusMokrassar","https://paypal.me/InsanusMokrassar?locale.x=ru_RU"],"categories":[],"sub_categories":[],"readme":"# krontab\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/krontab/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/krontab)\n\n[![Telegram Chat](https://img.shields.io/badge/Telegram%20Chat-0288D1?style=for-the-badge\u0026logo=telegram\u0026logoColor=white)](https://inmodev_chat.t.me)\n\n![JVM](https://img.shields.io/badge/JVM-red?style=for-the-badge\u0026logo=openjdk\u0026logoColor=white)\n![Android](https://img.shields.io/badge/Android-green?style=for-the-badge\u0026logo=android\u0026logoColor=white)\n![Js](https://img.shields.io/badge/JavaScript-323330?style=for-the-badge\u0026logo=javascript\u0026logoColor=F7DF1E)\n![Linux x64](https://img.shields.io/badge/Linux%20x64-white?style=for-the-badge\u0026logo=linux\u0026logoColor=black)\n![WASM](https://img.shields.io/badge/WASM-654FF0?style=for-the-badge\u0026logo=webassembly\u0026logoColor=white)\n\n[![KDocs](https://img.shields.io/badge/KDocs-323330?style=for-the-badge\u0026logo=Kotlin\u0026logoColor=7F52FF)](https://insanusmokrassar.github.io/krontab/)\n[![Tutorials](https://img.shields.io/badge/Tutorials-0288D1?style=for-the-badge\u0026logo=mkdocs\u0026logoColor=white)](https://docs.inmo.dev/krontab/index.html)\n\nLibrary was created to give oppotunity to launch some things from time to time according to some schedule in\nruntime of applications.\n\n## How to use\n\nThere are several ways to configure and use this library:\n\n* From some string\n* From builder\n\nAnyway, to start some action from time to time you will need to use one of extensions/functions:\n\n```kotlin\nval kronScheduler = /* creating of KronScheduler instance */;\n\nkronScheduler.doWhile {\n    // some action\n    true // true - repeat on next time\n}\n```\n\n### Including in project\n\nIf you want to include `krontab` in your project, just add next line to your\ndependencies part:\n\n```groovy\nimplementation \"dev.inmo:krontab:$krontab_version\"\n```\n\nNext version is the latest currently for the library:\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/krontab/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/krontab)\n\nFor old version of Gradle, instead of `implementation` word developers must use `compile`.\n\n### Config from string\n\nDevelopers can use more simple way to configure repeat times is string. String configuring\nlike a `crontab`, but with a little bit different meanings:\n\n```\n/--------------- Seconds\n| /------------- Minutes\n| | /----------- Hours\n| | | /--------- Days of months\n| | | | /------- Months\n| | | | | /----- (optional) Year\n| | | | | | /--- (optional) Timezone offset\n| | | | | | |  / (optional) Week days\n* * * * * * 0o *w\n```\n\nIt is different with original `crontab` syntax for the reason, that expected that in practice developers\nwill use seconds and minutes with more probability than months (for example) or even years. In fact, developers will use\nsomething like:\n\n```kotlin\ndoWhile(\"/5 * * * *\") {\n    println(\"Called\")\n    true // true - repeat on next time\n}\n```\n\nAn other version:\n\n```kotlin\ndoInfinity(\"/5 * * * *\") {\n    println(\"Called\")\n}\n```\n\nBoth of examples will print `Called` message every five seconds.\n\n### Config via builder\n\nAlso, this library currently supports DSL for creating the same goals:\n\n```kotlin\nval kronScheduler = buildSchedule {\n    seconds {\n        from (0) every 5\n    }\n}\nkronScheduler.doWhile {\n    println(\"Called\")\n    true // true - repeat on next time\n}\n```\n\nOr\n\n```kotlin\nval kronScheduler = buildSchedule {\n    seconds {\n        0 every 5\n    }\n}\nkronScheduler.doWhile {\n    println(\"Called\")\n    true // true - repeat on next time\n}\n```\n\nOr\n\n```kotlin\nval kronScheduler = buildSchedule {\n    seconds {\n        0 every 5\n    }\n}\nkronScheduler.doInfinity {\n    println(\"Called\")\n}\n```\n\nAll of these examples will do the same things: print `Called` message every five seconds.\n\n### do\\* functions\n\nWith regular `doOnce`/`doWhile`/`doInfinity` there are two types of their variations: **local** and **timezoned**. Local\nvariations (`doOnceLocal`/`doWhileLocal`/`doInfinityLocal`) will pass `DateTime` as an argument into the block:\n\n```kotlin\ndoInfinityLocal(\"/5 * * * *\") {\n    println(it) // will print current date time\n}\n```\n\nTimezoned variations (`doOnceTz`/`doWhileTz`/`doInfinityTz`) will do the same thing but pass as an argument `DateTimeTz`:\n\n```kotlin\ndoInfinityTz(\"/5 * * * * 0o\") {\n    println(it) // will print current date time in UTC\n}\n```\n\nIt is useful in cases when you need to get the time of calling and avoid extra calls to system time.\n\n#### Helpful table for \n\n|  | No args | Local `DateTime` | Local `DateTimeTz` with offset of `KronScheduler` |\n|---| ------- | ---------------- | ------------------------------------------------- |\n| **Call only near time** | doOnce | doOnceLocal | doOnceTz |\n| **Call while condition is true** | doWhile | doWhileLocal | doWhileTz |\n| **Work infinity*** | doInfinity | doInfinityLocal | doInfinityTz |\n\n*Here there is an important notice, that `Work infinity` is not exactly `infinity`. Actually, that means that `do while\ncoroutine is alive` and in fact executing will be stopped when coroutine became cancelled.\n\n### KronScheduler as a Flow\n\nAny `KronScheduler`can e converted to a `Flow\u003cDateTime` using extension `asFlow`:\n\n```kotlin\nval kronScheduler = buildSchedule {\n    seconds {\n        0 every 1\n    }\n}\n\nval flow = kronScheduler.asFlow()\n```\n\nSo, in this case any operations related to flow are available and it is expected that they will work correctly. For\nexample, it is possible to use this flow with `takeWhile`:\n\n```kotlin\nflow.takeWhile {\n    condition()\n}.collect {\n    action()\n}\n```\n\n### Offsets\n\nOffsets in this library works via passing parameter ending with `o` in any place after `month` config. Currently\nthere is only one format supported for offsets: minutes of offsets. To use time zones you will need to call `next`\nmethod with `DateTimeTz` argument or `nextTimeZoned` method with any `KronScheduler` instance, but in case if this\nscheduler is not instance of `KronSchedulerTz` it will work like you passed just `DateTime`.\n\nBesides, in case you wish to use time zones explicitly, you will need to get `KronSchedulerTz`. It is possible by:\n\n* Using `createSimpleScheduler`/`buildSchedule`/`KrontabTemplate#toSchedule`/`KrontabTemplate#toKronScheduler` methods\nwith passing `defaultOffset` parameter\n* Using `SchedulerBuilder#build`/`createSimpleScheduler`/`buildSchedule`/`KrontabTemplate#toSchedule`/`KrontabTemplate#toKronScheduler`\nmethods with casting to `KronSchedulerTz` in case you are pretty sure that it is timezoned `KronScheduler`\n* Creating your own implementation of `KronSchedulerTz`\n\n### Note about week days\n\nUnlike original CRON, here week days:\n\n* Works as `AND`: cron date time will search first day which will pass requirement according all parameters including\nweek days\n* You may use any related to numbers syntax with week days: `0-3w`, `0,1,2,3w`, etc.\n* Week days (like years and offsets) are optional and can be placed anywhere after `month`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsanusmokrassar%2Fkrontab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsanusmokrassar%2Fkrontab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsanusmokrassar%2Fkrontab/lists"}