From c16b0622677d8e3a3e42e59674cb87ec5b35a486 Mon Sep 17 00:00:00 2001 From: vaclavt Date: Thu, 17 Feb 2022 20:46:20 +0100 Subject: [PATCH] cron-like functionality wip --- debug.lsp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/debug.lsp b/debug.lsp index 53d610b..f195368 100644 --- a/debug.lsp +++ b/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 @@ -25,10 +20,7 @@ (#t 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 @@ -66,17 +65,17 @@ (print "cron daemon started, waiting" wait_time "miliseconds for first run") ; (thread-sleep wait_time) (while (not cron::stop) - (def now (get-universal-time)) - (for e cron::entries + (def now (get-universal-time)) + (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)