cron-like functionality wip
This commit is contained in:
parent
7d939a49dd
commit
c16b062267
38
debug.lsp
38
debug.lsp
|
|
@ -1,7 +1,5 @@
|
|||
(include "/usr/local/var/mlisp/terminal.lsp")
|
||||
|
||||
; TODO better env formating
|
||||
; TODO time parse function
|
||||
|
||||
|
||||
(defn cron::sleep-to-next-minute ()
|
||||
|
|
@ -9,9 +7,6 @@
|
|||
|
||||
|
||||
(defn cron::eval-time-spec (val time_spec)
|
||||
(do
|
||||
;(print "DEBUG" "cron::eval-time-spec" val time_spec)
|
||||
(def r
|
||||
(cond
|
||||
((nil? time_spec)
|
||||
#t) ; no time_spec -> it's true
|
||||
|
|
@ -26,9 +21,6 @@
|
|||
nil) ; TODO exception
|
||||
)
|
||||
)
|
||||
(print "val:" val "time_spec:" time_spec "result" r)
|
||||
r
|
||||
))
|
||||
|
||||
|
||||
(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_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"))))
|
||||
(print "time-to-run test" bool)
|
||||
; (print "time-to-run test" 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 ()
|
||||
(do
|
||||
|
|
@ -70,13 +69,13 @@
|
|||
(for e cron::entries
|
||||
(def job_name (first e))
|
||||
(def time_spec (second e))
|
||||
(def job_code (third e))
|
||||
|
||||
; (print "DEBUG" "checking" job_name "time_spec" time_spec)
|
||||
(if (cron::time-to-run now time_spec)
|
||||
(do
|
||||
;(print "running job:" job_name "code:" (third e))
|
||||
(thread-create (eval (third e)))
|
||||
)
|
||||
; (print "\n\n")
|
||||
(def is_for_run (cron::time-to-run now time_spec))
|
||||
; (print "DEBUG" job_name "checked" is_for_run)
|
||||
(if is_for_run
|
||||
(cron::run-job job_name job_code)
|
||||
; (print "not running" job_name)
|
||||
)
|
||||
)
|
||||
|
|
@ -99,19 +98,20 @@
|
|||
|
||||
(cron::add-job "every_min_print"
|
||||
'(("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"
|
||||
'(("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"
|
||||
'(("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"
|
||||
'(("weekday" "1-5")("hour" "15")("minute" "20"))
|
||||
'(print "code: 15:20_working_day"))
|
||||
'(print "executing: 15:20_working_day"))
|
||||
|
||||
|
||||
(cron::start)
|
||||
|
|
|
|||
Loading…
Reference in New Issue