540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
(define (dbfile:insert-or-update-process nsdb dat)
(let* ((host (procinf-host dat))
(pid (procinf-pid dat))
(curr-info (dbfile:get-process-info nsdb host pid)))
(if curr-info ;; record exists, do update
(match curr-info
((host port pid starttime status purpose dbname mtversion)
(sqlite3:execute
nsdb
"UPDATE processes SET port=?,starttime=?,status=?,
purpose=?,dbname=?,mtversion=?
WHERE host=? AND pid=?;"
(or (procinf-port dat) port)
(or (procinf-start dat) starttime)
(or (procinf-status dat) status)
(or (procinf-purpose dat) purpose)
(or (procinf-dbname dat) dbname)
(or (procinf-mtversion dat) mtversion)
host pid))
(else
#f ;; what to do?
))
(dbfile:register-process
nsdb
(procinf-host dat)
(procinf-port dat)
(procinf-pid dat)
(procinf-start dat)
(procinf-status dat)
(procinf-purpose dat)
(procinf-dbname dat)
(procinf-mtversion dat)))))
(define (dbfile:register-process nsdb host port pid starttime status purpose dbname mtversion)
(sqlite3:execute nsdb "INSERT INTO processes (host,port,pid,starttime,status,purpose,dbname,mtversion) VALUES (?,?,?,?,?,?,?,?);"
host port pid starttime status purpose dbname mtversion))
(define (dbfile:set-process-status nsdb host pid newstatus)
(sqlite3:execute nsdb "UPDATE processes SET status=? WHERE host=? AND pid=?;" newstatus host pid))
(define (dbfile:get-process-options nsdb purpose dbname)
(sqlite3:fold-row
;; host port pid starttime status mtversion
(lambda (res . row)
(cons row res))
'()
nsdb
"SELECT host,port,pid,starttime,status,mtversion FROM processes WHERE purpose=? AND dbname LIKE ? AND status='alive';"
purpose dbname))
(define (dbfile:get-process-info nsdb host pid)
(let ((res (sqlite3:fold-row
;; host port pid starttime status mtversion
(lambda (res . row)
(cons row res))
'()
nsdb
"SELECT host,port,pid,starttime,status,purpose,dbname,mtversion FROM processes WHERE host=? AND pid=?;"
host pid)))
(if (null? res)
#f
(car res))))
(define (dbfile:set-process-done nsdb host pid reason)
(sqlite3:execute nsdb "UPDATE processes SET status='ended',endtime=?,reason=? WHERE host=? AND pid=?;" (current-seconds) reason host pid)
|
|
|
>
>
|
|
|
|
|
|
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
|
(define (dbfile:insert-or-update-process nsdb dat)
(let* ((host (procinf-host dat))
(pid (procinf-pid dat))
(curr-info (dbfile:get-process-info nsdb host pid)))
(if curr-info ;; record exists, do update
(match curr-info
((host port pid starttime endtime status purpose dbname mtversion)
(sqlite3:execute
nsdb
"UPDATE processes SET port=?,starttime=?,endtime=?,status=?,
purpose=?,dbname=?,mtversion=?
WHERE host=? AND pid=?;"
(or (procinf-port dat) port)
(or (procinf-start dat) starttime)
(or (procinf-end dat) endtime)
(or (procinf-status dat) status)
(or (procinf-purpose dat) purpose)
(or (procinf-dbname dat) dbname)
(or (procinf-mtversion dat) mtversion)
host pid))
(else
#f ;; what to do?
))
(dbfile:register-process
nsdb
(procinf-host dat)
(procinf-port dat)
(procinf-pid dat)
(procinf-start dat)
(procinf-end dat)
(procinf-status dat)
(procinf-purpose dat)
(procinf-dbname dat)
(procinf-mtversion dat)))))
(define (dbfile:register-process nsdb host port pid starttime endtime status purpose dbname mtversion)
(sqlite3:execute nsdb "INSERT INTO processes (host,port,pid,starttime,endtime,status,purpose,dbname,mtversion) VALUES (?,?,?,?,?,?,?,?,?);"
host port pid starttime endtime status purpose dbname mtversion))
(define (dbfile:set-process-status nsdb host pid newstatus)
(sqlite3:execute nsdb "UPDATE processes SET status=? WHERE host=? AND pid=?;" newstatus host pid))
(define (dbfile:get-process-options nsdb purpose dbname)
(sqlite3:fold-row
;; host port pid starttime status mtversion
(lambda (res . row)
(cons row res))
'()
nsdb
"SELECT host,port,pid,starttime,endtime,status,mtversion FROM processes WHERE purpose=? AND dbname LIKE ? AND status='alive';"
purpose dbname))
(define (dbfile:get-process-info nsdb host pid)
(let ((res (sqlite3:fold-row
;; host port pid starttime status mtversion
(lambda (res . row)
(cons row res))
'()
nsdb
"SELECT host,port,pid,starttime,endtime,status,purpose,dbname,mtversion FROM processes WHERE host=? AND pid=?;"
host pid)))
(if (null? res)
#f
(car res))))
(define (dbfile:set-process-done nsdb host pid reason)
(sqlite3:execute nsdb "UPDATE processes SET status='ended',endtime=?,reason=? WHERE host=? AND pid=?;" (current-seconds) reason host pid)
|