Index: dbfile.scm ================================================================== --- dbfile.scm +++ dbfile.scm @@ -16,11 +16,11 @@ ;; You should have received a copy of the GNU General Public License ;; along with Megatest. If not, see . ;;====================================================================== -(use srfi-18) +(use srfi-18 posix hostinfo) (declare (unit dbfile)) (declare (uses debugprint)) (declare (uses commonmod)) @@ -32,18 +32,19 @@ data-structures extras matchable (prefix sqlite3 sqlite3:) - posix typed-records + posix posix-extras typed-records srfi-18 srfi-1 srfi-69 stack files ports + hostinfo commonmod debugprint ) @@ -121,10 +122,29 @@ (define-record simple-run target id runname state status owner event_time) (define-record-printer (simple-run x out) (fprintf out "#,(simple-run ~S ~S ~S ~S)" (simple-run-target x) (simple-run-id x) (simple-run-runname x) (time->string (seconds->local-time (simple-run-event_time x) )))) +;; megatest process tracking + +(defstruct pinf + (start (current-seconds)) + (host (get-host-name)) ;; why is this not being recognised? + (pid (current-process-id)) + (port #f) + (cwd (current-directory)) + (load #f) + (purpose #f) ;; get-purpose needed + (dbname #f) + (mtbin (car (argv))) + (mtversion #f) + (status "running") + + + ) + +(define *pinf* (make-pinf)) (define *dbstruct-dbs* #f) (define *db-open-mutex* (make-mutex)) (define *db-access-mutex* (make-mutex)) ;; used in common.scm (define *no-sync-db* #f) (define *db-sync-in-progress* #f) @@ -493,10 +513,33 @@ (sqlite3:execute db "PRAGMA synchronous = 0;") (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 136000)))) db)) ;; processes table calls + +(define (dbfile:insert-or-update-process nsdb pinfdat) + (let* ((host (pinf-host pinfdat)) + (pid (pinf-pid pinfdat)) + (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) + (dbfile:register-process nsdb host port pid starttime status purpose dbname mtversion)) + (else + #f ;; what to do? + )) + (dbfile:register-process + nsdb + (pinf-host pinfdat) + (pinf-port pinfdat) + (pinf-pid pinfdat) + (pinf-start pinfdat) + (pinf-status pinfdat) + (pinf-purpose pinfdat) + (pinf-dbname pinfdat) + (pinf-mtversion pinfdat))))) + (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)) @@ -510,10 +553,23 @@ (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,mtversionn 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) (dbfile:cleanup-old-entries nsdb)) Index: launch.scm ================================================================== --- launch.scm +++ launch.scm @@ -32,13 +32,13 @@ (declare (uses ezsteps)) ;; (declare (uses dbmod)) (declare (uses dbfile)) (declare (uses mtargs)) -(use regex regex-case base64 sqlite3 srfi-18 directory-utils posix-extras z3 - call-with-environment-variables csv) -(use typed-records pathname-expand matchable) +(use regex regex-case base64 sqlite3 srfi-18 directory-utils posix posix-extras z3 + call-with-environment-variables csv hostinfo + typed-records pathname-expand matchable) (import (prefix base64 base64:) (prefix sqlite3 sqlite3:) (prefix mtargs args:) )