cron-like functionality wip
This commit is contained in:
parent
7d939a49dd
commit
c16b062267
44
debug.lsp
44
debug.lsp
|
|
@ -1,7 +1,5 @@
|
||||||
(include "/usr/local/var/mlisp/terminal.lsp")
|
(include "/usr/local/var/mlisp/terminal.lsp")
|
||||||
|
|
||||||
; TODO better env formating
|
|
||||||
; TODO time parse function
|
|
||||||
|
|
||||||
|
|
||||||
(defn cron::sleep-to-next-minute ()
|
(defn cron::sleep-to-next-minute ()
|
||||||
|
|
@ -9,9 +7,6 @@
|
||||||
|
|
||||||
|
|
||||||
(defn cron::eval-time-spec (val time_spec)
|
(defn cron::eval-time-spec (val time_spec)
|
||||||
(do
|
|
||||||
;(print "DEBUG" "cron::eval-time-spec" val time_spec)
|
|
||||||
(def r
|
|
||||||
(cond
|
(cond
|
||||||
((nil? time_spec)
|
((nil? time_spec)
|
||||||
#t) ; no time_spec -> it's true
|
#t) ; no time_spec -> it's true
|
||||||
|
|
@ -25,10 +20,7 @@
|
||||||
(#t
|
(#t
|
||||||
nil) ; TODO exception
|
nil) ; TODO exception
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
(print "val:" val "time_spec:" time_spec "result" r)
|
|
||||||
r
|
|
||||||
))
|
|
||||||
|
|
||||||
|
|
||||||
(defn cron::add-job (name time_spec job)
|
(defn cron::add-job (name time_spec job)
|
||||||
|
|
@ -55,10 +47,17 @@
|
||||||
(set! bool (and bool (cron::eval-time-spec time_day (find-val-in-list time_spec "day"))))
|
(set! bool (and bool (cron::eval-time-spec time_day (find-val-in-list time_spec "day"))))
|
||||||
(set! bool (and bool (cron::eval-time-spec time_month (find-val-in-list time_spec "month"))))
|
(set! bool (and bool (cron::eval-time-spec time_month (find-val-in-list time_spec "month"))))
|
||||||
(set! bool (and bool (cron::eval-time-spec time_year (find-val-in-list time_spec "year"))))
|
(set! bool (and bool (cron::eval-time-spec time_year (find-val-in-list time_spec "year"))))
|
||||||
(print "time-to-run test" bool)
|
; (print "time-to-run test" bool)
|
||||||
bool
|
bool
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(defn cron::run-job (name code)
|
||||||
|
(do
|
||||||
|
;(print "running job:" name "->" code)
|
||||||
|
(def run_code (+ "(thread-create " (display code) ")"))
|
||||||
|
(eval (parse run_code))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
(defn cron::start ()
|
(defn cron::start ()
|
||||||
(do
|
(do
|
||||||
|
|
@ -66,17 +65,17 @@
|
||||||
(print "cron daemon started, waiting" wait_time "miliseconds for first run")
|
(print "cron daemon started, waiting" wait_time "miliseconds for first run")
|
||||||
; (thread-sleep wait_time)
|
; (thread-sleep wait_time)
|
||||||
(while (not cron::stop)
|
(while (not cron::stop)
|
||||||
(def now (get-universal-time))
|
(def now (get-universal-time))
|
||||||
(for e cron::entries
|
(for e cron::entries
|
||||||
(def job_name (first e))
|
(def job_name (first e))
|
||||||
(def time_spec (second e))
|
(def time_spec (second e))
|
||||||
|
(def job_code (third e))
|
||||||
|
|
||||||
; (print "DEBUG" "checking" job_name "time_spec" time_spec)
|
; (print "\n\n")
|
||||||
(if (cron::time-to-run now time_spec)
|
(def is_for_run (cron::time-to-run now time_spec))
|
||||||
(do
|
; (print "DEBUG" job_name "checked" is_for_run)
|
||||||
;(print "running job:" job_name "code:" (third e))
|
(if is_for_run
|
||||||
(thread-create (eval (third e)))
|
(cron::run-job job_name job_code)
|
||||||
)
|
|
||||||
; (print "not running" job_name)
|
; (print "not running" job_name)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -99,19 +98,20 @@
|
||||||
|
|
||||||
(cron::add-job "every_min_print"
|
(cron::add-job "every_min_print"
|
||||||
'(("minute" "*"))
|
'(("minute" "*"))
|
||||||
'(print "code: every_min_print"))
|
'(print "executing: every_min_print"))
|
||||||
|
; '(do (sleep 3) (print "executing: every_min_print")))
|
||||||
|
|
||||||
(cron::add-job "every_min_between_00_and_05"
|
(cron::add-job "every_min_between_00_and_05"
|
||||||
'(("minute" "00-05"))
|
'(("minute" "00-05"))
|
||||||
'(print "code: every_min_between_00_and_05"))
|
'(print "executing: every_min_between_00_and_05"))
|
||||||
|
|
||||||
(cron::add-job "13:20_working_day"
|
(cron::add-job "13:20_working_day"
|
||||||
'(("weekday" "1-5")("hour" "13")("minute" "20"))
|
'(("weekday" "1-5")("hour" "13")("minute" "20"))
|
||||||
'(print "code: 13:20_working_day"))
|
'(print "executing: 13:20_working_day"))
|
||||||
|
|
||||||
(cron::add-job "15:20_working_day"
|
(cron::add-job "15:20_working_day"
|
||||||
'(("weekday" "1-5")("hour" "15")("minute" "20"))
|
'(("weekday" "1-5")("hour" "15")("minute" "20"))
|
||||||
'(print "code: 15:20_working_day"))
|
'(print "executing: 15:20_working_day"))
|
||||||
|
|
||||||
|
|
||||||
(cron::start)
|
(cron::start)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue