Megatest

Diff
Login

Differences From Artifact [0892af02f7]:

To Artifact [0f03b1a388]:


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
;;
;;  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")







|
|
>
|
|
>



|


|
|
|

|
|
>
>
>
>
>
|
<
|
|
>
|
|
|
|
<
>
>
|
|
>
|
|
|
<
>
>
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|







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
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
;;
;;  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 now-seconds-in last-done) ;; ref-seconds = #f is NOW. 
  (let* ((cron-items     (map string->number (string-split cron-str)))
	 (now-seconds    (or now-seconds-in (current-seconds)))
	 (now-time       (seconds->local-time now-seconds))
	 (last-done-time (seconds->local-time last-done))
	 (all-times      (make-hash-table)))
    (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 (((     cmin chour cdayofmonth cmonth    cdayofweek)
		     cron-items)
		    ;; 0     1    2        3         4    5      6
		    ((nsec nmin nhour ndayofmonth nmonth nyr ndayofweek n7 n8 n9)
		     (vector->list now-time))
		    ((lsec lmin lhour ldayofmonth lmonth lyr ldayofweek l7 l8 l9)
		     (vector->list last-done-time)))
	  ;; create all possible time slots
	  ;; remove invalid slots due to (for example) day of week
	  ;; get the start and end entries for the ref-seconds (current) time
	  ;; if last-done > ref-seconds => this is an ERROR!
	  ;; does the last-done time fall in the legit region?
	  ;;    yes => #f  do not run again this command
	  ;;    no  => #t  ok to run the command
	  (for-each ;; month

	   (lambda (month)
	     (for-each ;; dayofmonth
	      (lambda (dom)
		(for-each
		 (lambda (hr) ;; hour
		   (for-each
		    (lambda (minute) ;; minute

		      (let ((copy-now (apply vector (vector->list now-time))))
			(vector-set! copy-now 0 0) ;; force seconds to zero
			(vector-set! copy-now 1 minute)
			(vector-set! copy-now 2 hr)
			(vector-set! copy-now 3 dom)  ;; dom is already corrected for zero referenced
			(vector-set! copy-now 4 month)
			(let* ((copy-now-secs (local-time->seconds copy-now))
			       (new-copy      (seconds->local-time copy-now-secs))) ;; remake the time vector

			  (if (or (not cdayofweek)
				  (equal? (vector-ref new-copy 6)
					  cdayofweek)) ;; if the day is specified and a match OR if the day is NOT specified
			      (if (or (not cdayofmonth)
				      (equal? (vector-ref new-copy 3)
					      (+ 1 cdayofmonth))) ;; if the month is specified and a match OR if the month is NOT specified
				  (hash-table-set! all-times copy-now-secs new-copy))))))
		    (if cmin
			`(,cmin)  ;; if given cmin, have to use it
			(list (- nmin 1) nmin (+ nmin 1))))) ;; minute
		 (if chour
		     `(,chour)
		     (list (- nhour 1) nhour (+ nhour 1))))) ;; hour
	      (if cdayofmonth
		  `(,cdayofmonth)
		  (list (- ndayofmonth 1) ndayofmonth (+ ndayofmonth 1)))))
	   (if cmonth
	       `(,cmonth)
	       (list (- nmonth 1) nmonth (+ nmonth 1))))
	  (let ((before #f)
		(is-in  #f))
	    (for-each
	     (lambda (moment)
	       (if (and before
			(<= before now-seconds)
			(>= moment now-seconds))
		   (begin
		     (print)
		     (print "Before: " (time->string (seconds->local-time before)))
		     (print "Now:    " (time->string (seconds->local-time now-seconds)))
		     (print "After:  " (time->string (seconds->local-time moment)))
		     (print "Last:   " (time->string (seconds->local-time last-done)))
		     (if (<  last-done before)
			 (set! is-in before))
		     ))
	       (set! before moment))
	     (sort (hash-table-keys all-times) <))
	    is-in)))))

;;======================================================================
;; C O L O R S
;;======================================================================
      
(define (common:name->iup-color name)
  (case (string->symbol (string-downcase name))
    ((red)    "223 33 49")