aika
Clojure time-based job scheduler. Jobs are scheduled using psuedo cron-tabs
"Equation-wise the first thing to do is to consider time as officially ended.
We work on the other side of time."
— Sun Ra
Install
Add the following dependency to your project.clj file:
[aika "0.0.33-alpha"]Cron
The namespace for the date side of things is aika.cron
(:require [aika.cron :refer :all]))Aika's cron tabs have 5 arguments:
-
minutebetween 0 - 59 -
hourbetween 1 - 24 -
daybetween 1 - 30 -
monthbetween 1 - 12 -
weekdaybetween 0 - 6
Optionally, a DateTime instance can be provided as the first argument
Examples
Run on the 50th minute of every hour of every day of every month
(valid-tab? [50 * * * *]) ;; trueRun on minutes divisible by 10: 0,10,20,30...
(valid-tab? [(%minutes 10) * * * *]) ;; trueRun every three hours on Sunday's and Monday's
(valid-tab? [* (%hours 3) * * (range 0 2)]) ;; trueSchedule every three days from 1969
(parse-tab [(clj-time.core/data-time 1969) * * (%days 3) * *])
;; #<DateTime 1969-01-03...>Tab->msec
(tab->msec [(%minutes 1) * * * *]) ;; 60000Job
The namespace for the job scheduling side of things is aika.core
(:require [aika.core :refer :all]
[aika.cron :refer :all])Defining a job
You can define a job using the defjob macro
Here is an example of a job that prints 'Hfeflflfo' every minute
(defjob hello-world [(%minutes 1) * * * *]
(println "Hfeflflfo")
;; #'user/hello-worldScheduling a job
You can schedule a job by calling the schedule function
This function starts a job and returns the status map
(schedule hello-world)You can check to see if a job has been scheduled by calling the scheduled? function
(scheduled? hello-world) ;; trueJob status
You can retrieve a job's status by calling the status function
This returns a map containing:
-
:cycles- the number of times the task has run -
:scheduled?- has the job been scheduled? -
:scheduled-last- DateTime instance of when the last task was run -
:scheduled-next- DateTime instance of when the next task will run
(status hello-world) ;; {:cycles 0, :scheduled :true...}Stopping a job
You can stop a job by calling the stop function
(stop hello-world)License
Copyright © 2014 Kibu
Distributed under the Eclipse Public License version 1.0