Overview
Comment: | Added a simple crontab-like function for time based triggers |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | run-mgr |
Files: | files | file ages | folders |
SHA1: |
27f026b7305a682fa3b0e64f14dc7e53 |
User & Date: | matt on 2017-02-18 22:15:23 |
Other Links: | branch diff | manifest | tags |
Context
2017-02-18
| ||
22:40 | Added basic crontab based launching check-in: 5d3a3776be user: matt tags: run-mgr | |
22:15 | Added a simple crontab-like function for time based triggers check-in: 27f026b730 user: matt tags: run-mgr | |
2017-02-16
| ||
22:06 | Fixed launching of viewscreen causing hesitation on cleanrunexecute check-in: d2a7fb2fe4 user: matt tags: run-mgr | |
Changes
Modified common.scm from [e8e9c53bae] to [0892af02f7].
︙ | ︙ | |||
1686 1687 1688 1689 1690 1691 1692 | '( y mo w d h m s)))) (list 8 6 5 2 1))) '(5 10 15 20 30 40 50 500)) (if values (apply values result) (values 0 day 1 0 'd)))) | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 | '( y mo w d h m s)))) (list 8 6 5 2 1))) '(5 10 15 20 30 40 50 500)) (if values (apply values result) (values 0 day 1 0 'd)))) ;; given a cron string and the last time event was processed return #t to run or #f to not run ;; ;; min hour dayofmonth month dayofweek ;; 0-59 0-23 1-31 1-12 0-6 ### NOTE: dayofweek does not include 7 ;; ;; #t => yes, run the job ;; #f => no, do not run the job ;; (define (common:cron-event cron-str ref-seconds last-done) ;; ref-seconds = #f is NOW. (let ((cron-items (map string->number (string-split cron-str))) (ref-time (seconds->local-time (or ref-seconds (current-seconds)))) (last-done-time (seconds->local-time last-done))) (print "cron-items: " cron-items "(length cron-items): " (length cron-items)) (if (not (eq? (length cron-items) 5)) ;; don't even try to figure out junk strings #f (match-let ((( min hour dayofmonth month dayofweek) cron-items) ;; 0 1 2 3 4 5 6 ((rsec rmin rhour rdayofmonth rmonth ryr rdayofweek r7 r8 r9) (vector->list ref-time)) ((csec cmin chour cdayofmonth cmonth cyr cdayofweek c7 c8 c9) (vector->list last-done-time))) (let ((have-match (and (or (not dayofweek) (eq? dayofweek rdayofweek)) ;; either any dayofweek or they are same (or (not month) (eq? month (+ rmonth 1))) ;; posix time month is 0-11 (or (not dayofmonth) (eq? dayofmonth rdayofmonth)))) (hour-match (or (not hour) (eq? hour rhour))) (min-match (or (not min) (eq? min rmin)))) ;; now inject non-"*" times into the ref-time (vector-set! ref-time 0 0) ;; set seconds to zero (if min (vector-set! ref-time 1 min)) (if hour (vector-set! ref-time 2 hour)) (let* ((ref-transition-seconds (local-time->seconds ref-time)) (done-since (> last-done ref-transition-seconds))) ;; (print "have-match: " have-match " hour-match: " hour-match " min-match: " min-match " ref-transition-seconds - last-done: " (- ref-transition-seconds last-done) " done-since: " done-since) (and have-match (not done-since)))))))) ;;====================================================================== ;; C O L O R S ;;====================================================================== (define (common:name->iup-color name) (case (string->symbol (string-downcase name)) ((red) "223 33 49") |
︙ | ︙ |
Modified mtut.scm from [a17ee21a60] to [28506ee857].
︙ | ︙ | |||
242 243 244 245 246 247 248 | (if (not exists) (let* ((pktdat (string-intersperse (with-input-from-file pkt read-lines) "\n")) (apkt (convert-pkt->alist pktdat)) (ptype (alist-ref 'T apkt))) (add-to-queue pdb pktdat uuid (or ptype 'cmd) #f 0) | | | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | (if (not exists) (let* ((pktdat (string-intersperse (with-input-from-file pkt read-lines) "\n")) (apkt (convert-pkt->alist pktdat)) (ptype (alist-ref 'T apkt))) (add-to-queue pdb pktdat uuid (or ptype 'cmd) #f 0) (debug:print 4 *default-log-port* "Added " uuid " of type " ptype " to queue")) (debug:print 4 *default-log-port* "pkt: " uuid " exists, skipping...") ))) pkts)))) (string-split pktsdirs))))) ;;====================================================================== ;; Runs ;;====================================================================== |
︙ | ︙ |
Added tests/unittests/cron.scm version [700c4402ed].
> > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | (use test) ;; S M H MD MTH YR WD (define ref-time (vector 58 39 21 18 1 117 6 48 #f 25200)) (for-each (lambda (situation crontab ref-seconds last-done expected) (print "\nsituation: " situation) (print "ref-seconds: " ref-seconds " = " (time->string (seconds->local-time ref-seconds))) (print "last-done: " last-done " = " (time->string (seconds->local-time last-done))) (print "crontab: " crontab) (test #f expected (common:cron-event crontab ref-seconds last-done))) '("midnight" "midnight, already done" "diffdate" "diffdate, already done" "diffday" "sameday, already done") '("0 0 * * *" "0 0 * * *" "0 0 18 * *" "0 0 18 * *" "0 0 * * 5" "0 0 18 * 6" ) '(1487489998.0 1487489998.0 1487489998.0 1487489998.0 1487489998.0 1487489998.0 ) '(1487479198.0 1487489098.0 1487479198.0 1487489098.0 1487479198.0 1487489098.0 ) '( #t #f #f #f #f #f ) ) |