239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
-
-
+
+
+
+
+
+
-
+
+
|
;;
(define (make-runname pre post)
(time->string
(seconds->local-time (current-seconds)) "%Yw%V.%w-%H%M"))
;; collect, translate, collate and assemble a pkt from the command-line
;;
(define (command-line->pkt action args-alist)
(let* ((args-data (if args-alist
(define (command-line->pkt action args-alist sched-in)
(let* ((sched (cond
((vector? sched-in)(local-time->seconds sched-in)) ;; we recieved a time
((number? sched-in) sched-in)
(else (current-seconds))))
(args-data (if args-alist
args-alist
(hash-table->alist args:arg-hash)))
(alldat (apply append (list 'a action
'U (current-user-name))
'U (current-user-name)
'D sched)
(map (lambda (x)
(let* ((param (car x))
(value (cdr x))
(pmeta (assoc param *arg-keys*))
(smeta (assoc param *switch-keys*))
(meta (if (or pmeta smeta)
(cdr (or pmeta smeta))
|
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
-
+
-
+
+
|
;; NEED TIMESTAMP ON PKTS for efficient loading of packets into db.
;; make a run request pkt from basic data
;;
(define (create-run-pkt mtconf area runkey runname mode-patt tag-expr pktsdir reason contour)
(define (create-run-pkt mtconf area runkey runname mode-patt tag-expr pktsdir reason contour sched)
(let ((area-path (configf:lookup mtconf "areas" area)))
(let-values (((uuid pkt)
(command-line->pkt
"run"
(append
`(("-target" . ,runkey)
("-run-name" . ,runname)
("-start-dir" . ,area-path)
("-msg" . ,reason)
("-contour" . ,contour))
(if mode-patt
`(("-mode-patt" . ,mode-patt))
'())
(if tag-expr
`(("-tag-expr" . ,tag-expr))
'())
(if (not (or mode-patt tag-expr))
`(("-item-patt" . "%"))
'())))))
'()))
sched)))
(with-output-to-file
(conc pktsdir "/" uuid ".pkt")
(lambda ()
(print pkt))))))
;; collect all needed data and create run pkts for contours with changed inputs
;;
|
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
-
+
+
-
+
-
+
-
+
-
+
-
+
+
+
-
-
-
-
+
+
+
+
+
|
(if (not (eq? (length valparts) 6))
(print "ERROR: bad sense spec \"" (string-intersperse sense " ") "\"")
(let* ((run-name (car valparts))
(crontab (string-intersperse (cdr valparts)))
(last-run (if (null? starttimes) ;; never run
0
(apply max (map cdr starttimes))))
(need-run (common:cron-event crontab #f last-run)))
(need-run (common:cron-event crontab #f last-run))
(runname (if need-run (conc "sched" (time->string (seconds->local-time (current-seconds)) "%M%H%d")))))
(print "last-run: " last-run " need-run: " need-run)
(if need-run
(configf:section-var-set! torun contour runkey `(,(conc ruletype ":" (string-intersperse (cdr valparts) "-")) ,runname))))))
(configf:section-var-set! torun contour runkey `(,(conc ruletype ":" (string-intersperse (cdr valparts) "-")) ,runname ,need-run))))))
((file file-or) ;; one or more files must be newer than the reference
(let* ((file-globs (cdr valparts))
(youngestdat (common:get-youngest file-globs))
(youngestmod (car youngestdat)))
;; (print "youngestmod: " youngestmod " starttimes: " starttimes)
(if (null? starttimes) ;; this target has never been run
(configf:section-var-set! torun contour runkey `("file:neverrun" ,runname))
(for-each
(lambda (starttime) ;; look at the time the last run was kicked off for this contour
(if (> youngestmod (cdr starttime))
(begin
(print "starttime younger than youngestmod: " starttime " Youngestmod: " youngestmod)
(configf:section-var-set! torun contour runkey `(,(conc ruletype ":" (cadr youngestdat)) ,runname)))))
(configf:section-var-set! torun contour runkey `(,(conc ruletype ":" (cadr youngestdat)) ,runname #f)))))
starttimes))
))
((file-and) ;; all files must be newer than the reference
(let* ((file-globs (cdr valparts))
(youngestdat (common:get-youngest file-globs))
(youngestmod (car youngestdat))
(success #t)) ;; any cases of not true, set flag to #f for AND
;; (print "youngestmod: " youngestmod " starttimes: " starttimes)
(if (null? starttimes) ;; this target has never been run
(configf:section-var-set! torun contour runkey `("file:neverrun" ,runname))
(configf:section-var-set! torun contour runkey `("file:neverrun" ,runname #f))
(for-each
(lambda (starttime) ;; look at the time the last run was kicked off for this contour
(if (< youngestmod (cdr starttime))
(set! success #f)))
starttimes))
(if success
(begin
(print "starttime younger than youngestmod: " starttime " Youngestmod: " youngestmod)
(configf:section-var-set! torun contour runkey `(,(conc ruletype ":" (cadr youngestdat)) ,runname))))))
(configf:section-var-set! torun contour runkey `(,(conc ruletype ":" (cadr youngestdat)) ,runname #f))))))
)))
keydats)))
(hash-table-keys rgconf))
;; now have torun populated
;; now have to run populated
(for-each
(lambda (contour)
(let* ((mode-tag (string-split (or (configf:lookup mtconf "contours" contour) "") "/"))
(mode-patt (if (eq? (length mode-tag) 2)(cadr mode-tag) #f))
(tag-expr (if (null? mode-tag) #f (car mode-tag))))
(for-each
(lambda (runkeydat)
(let* ((runkey (car runkeydat))
(info (cadr runkeydat)))
(for-each
(lambda (area)
(if (< (length info) 3)
(print "ERROR: bad info data for " contour ", " runkey ", " area)
(let ((runname (cadr info))
(reason (car info)))
(print "runkey: " runkey " contour: " contour " info: " info " area: " area " tag-expr: " tag-expr " mode-patt: " mode-patt)
(create-run-pkt mtconf area runkey runname mode-patt tag-expr pktsdir reason contour)))
(let ((runname (cadr info))
(reason (car info))
(sched (caddr info)))
(print "runkey: " runkey " contour: " contour " info: " info " area: " area " tag-expr: " tag-expr " mode-patt: " mode-patt)
(create-run-pkt mtconf area runkey runname mode-patt tag-expr pktsdir reason contour sched))))
areas)))
(configf:get-section torun contour))))
(hash-table-keys torun))))))
(define (pkt->cmdline pkta)
(fold (lambda (a res)
|