{"id":26956288,"url":"https://github.com/vodori/chronology","last_synced_at":"2025-04-03T03:21:10.307Z","repository":{"id":57729495,"uuid":"147990074","full_name":"vodori/chronology","owner":"vodori","description":"A lightweight scheduler and infinite sequences from cron expressions.","archived":false,"fork":false,"pushed_at":"2022-12-16T02:04:18.000Z","size":24,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2023-08-12T18:22:10.095Z","etag":null,"topics":["clojure","cron","crontab","quartz","scheduler"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vodori.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-09T03:32:38.000Z","updated_at":"2023-04-02T07:59:14.000Z","dependencies_parsed_at":"2023-01-29T08:00:13.521Z","dependency_job_id":null,"html_url":"https://github.com/vodori/chronology","commit_stats":null,"previous_names":[],"tags_count":3,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vodori%2Fchronology","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vodori%2Fchronology/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vodori%2Fchronology/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vodori%2Fchronology/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vodori","download_url":"https://codeload.github.com/vodori/chronology/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246928391,"owners_count":20856284,"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":["clojure","cron","crontab","quartz","scheduler"],"created_at":"2025-04-03T03:21:09.712Z","updated_at":"2025-04-03T03:21:10.243Z","avatar_url":"https://github.com/vodori.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/vodori/chronology.svg?branch=develop)](https://travis-ci.com/vodori/chronology) [![Maven metadata URL](https://img.shields.io/maven-metadata/v/https/repo1.maven.org/maven2/com/vodori/chronology/maven-metadata.xml.svg)](https://mvnrepository.com/artifact/com.vodori/chronology)\n\n\n### Chronology\n\nA library for scheduling tasks using core.async according to cron expressions. Chronology also \nprovides forward and backward infinite sequences of DateTime objects for a given cron expression. \nCron expressions are in the style of [quartz](http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html).\n\n### Install\n\n```edn \n[com.vodori/chronology \"0.1.0\"]\n```\n\n### Usage\n\n___\n\n#### Cron sequences:\n\nChronology lets you convert a cron expression into an infinite sequence\nof DateTime instances. Internally it just does this and then converts the\nsequence into a channel by using [chime](https://github.com/jarohen/chime).\n\n```clojure\n\n(require '[chronology.utils :refer :all])\n\n(def tick (f/parse \"2000-01-01T00:00:00.000Z\"))\n\n(def cron \"0 */5 * * * ?\")\n\n(defn datetime-\u003eiso [dt] \n  (f/unparse (f/formatter :date-time) dt))\n  \n(def human-readable (explain-cron cron))\n;=\u003e \"every 5 minutes\"\n\n(-\u003e\u003e (forward-cron-sequence tick cron)\n     (map datetime-\u003eiso)\n     (take 5))\n     \n;=\u003e (\"2000-01-01T00:05:00.000Z\" \n;    \"2000-01-01T00:10:00.000Z\" \n;    \"2000-01-01T00:15:00.000Z\" \n;    \"2000-01-01T00:20:00.000Z\" \n;    \"2000-01-01T00:25:00.000Z\")\n\n\n(-\u003e\u003e (backward-cron-sequence tick cron)\n     (map datetime-\u003eiso)\n     (take 5))\n     \n;=\u003e (\"1999-12-31T23:55:00.000Z\" \n;    \"1999-12-31T23:50:00.000Z\" \n;    \"1999-12-31T23:45:00.000Z\" \n;    \"1999-12-31T23:40:00.000Z\" \n;    \"1999-12-31T23:35:00.000Z\")\n\n```\n\n___\n\n#### Scheduling tasks:\n\nTasks in chronology are just functions that receive a single `ctx` map.\nThe context is whatever context you provide when scheduling the function\nmerged with information maintained by the library itself (the task group, \ntask key, and the tick DateTime).\n\nYour function is always executed on a dedicated thread and the result is put onto a\nresult channel which is returned when you schedule the task. The result channel contains\nrecords of type Success or type Failure depending on if the function threw. Each result\nalso contains the full context and a duration of how long the task took to complete (or throw).\nThe result channel is unbuffered so you *must* take the result in order for the task to keep executing.\n\n```clojure\n\n(require '[chronology.core :refer :all])\n\n(def key     (make-key \"group1\" \"task1\"))\n(def cron    \"* * * * * ?\")\n(def context {:customerId 1})\n\n(defn task [{:keys [group key tick customerId] :as ctx}]\n  (send-emails-for customerId))\n\n(def result-chan (schedule-cron key cron task context))\n\n(async/go-loop []\n  (when-some [result (async/\u003c! result-chan)]\n    (if (failure? result) \n       (.printStackTrace (:error result))\n       (println (:result result))) \n    (recur)))\n```\n\n___ \n\n\n### License\nThis project is licensed under [MIT license](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvodori%2Fchronology","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvodori%2Fchronology","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvodori%2Fchronology/lists"}