1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
|
;; The queue is a list of vectors where the zeroth slot indicates the type of query to
;; apply and the second slot is the time of the query and the third entry is a list of
;; values to be applied
;;
(define (db:write-cached-data)
(open-run-close
(lambda (db . params)
(let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE id=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
(state-status-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=? WHERE id=?;"))
(step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
(data #f))
(mutex-lock! *incoming-mutex*)
(set! data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1)))))
(set! *incoming-data* '())
(mutex-unlock! *incoming-mutex*)
(if (> (length data) 0)
(debug:print 4 "INFO: Writing cached data " data))
(sqlite3:with-transaction
db
(lambda ()
(for-each (lambda (entry)
(debug:print 4 "INFO: flushing " entry " to db")
(case (vector-ref entry 0)
((meta-info)
(apply sqlite3:execute meta-stmt (vector-ref entry 2)))
((step-status)
(apply sqlite3:execute step-stmt (vector-ref entry 2)))
((state-status)
(apply sqlite3:execute state-status-stmt (vector-ref entry 2)))
(else
(debug:print 0 "ERROR: Queued entry not recognised " entry))))
data)))
(sqlite3:finalize! meta-stmt) ;; sqlite is the bottleneck, clear the statements asap?
(sqlite3:finalize! step-stmt)
(sqlite3:finalize! state-status-stmt)
))
#f))
;; (define (db:write-cached-data db)
;; (let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE id=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
;; (step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
;; (data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1))))))
|
|
|
>
|
|
>
>
>
|
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
|
;; The queue is a list of vectors where the zeroth slot indicates the type of query to
;; apply and the second slot is the time of the query and the third entry is a list of
;; values to be applied
;;
(define (db:write-cached-data)
(open-run-close
(lambda (db . params)
(let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE id=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
(state-status-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=? WHERE id=?;"))
(state-status-msg-stmt (sqlite3:prepare db "UPDATE tests SET state=?,status=?,comment=? WHERE id=?;"))
(step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
(data #f))
(mutex-lock! *incoming-mutex*)
(set! data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1)))))
(set! *incoming-data* '())
(mutex-unlock! *incoming-mutex*)
(if (> (length data) 0)
(debug:print 4 "INFO: Writing cached data " data))
(sqlite3:with-transaction
db
(lambda ()
(for-each (lambda (entry)
(debug:print 4 "INFO: flushing " entry " to db")
(case (vector-ref entry 0)
((meta-info)
(apply sqlite3:execute meta-stmt (vector-ref entry 2)))
((step-status)
(apply sqlite3:execute step-stmt (vector-ref entry 2)))
((state-status)
(apply sqlite3:execute state-status-stmt (vector-ref entry 2)))
((state-status-msg)
(apply sqlite3:execute state-status-msg-stmt (vector-ref entry 2)))
(else
(debug:print 0 "ERROR: Queued entry not recognised " entry))))
data)))
(sqlite3:finalize! meta-stmt) ;; sqlite is the bottleneck, clear the statements asap?
(sqlite3:finalize! step-stmt)
(sqlite3:finalize! state-status-stmt)
(sqlite3:finalize! state-status-msg-stmt)
))
#f))
;; (define (db:write-cached-data db)
;; (let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE id=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
;; (step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
;; (data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1))))))
|
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
|
(sqlite3:execute
db
"UPDATE tests
SET fail_count=(SELECT count(id) FROM tests WHERE run_id=? AND testname=? AND item_path != '' AND status='FAIL'),
pass_count=(SELECT count(id) FROM tests WHERE run_id=? AND testname=? AND item_path != '' AND (status='PASS' OR status='WARN' OR status='WAIVED'))
WHERE run_id=? AND testname=? AND item_path='';"
run-id test-name run-id test-name run-id test-name)
(thread-sleep! 0.1) ;; give other processes a chance here
(if (equal? status "RUNNING") ;; running takes priority over all other states, force the test state to RUNNING
(sqlite3:execute db "UPDATE tests SET state=? WHERE run_id=? AND testname=? AND item_path='';" "RUNNING" run-id test-name)
(sqlite3:execute
db
"UPDATE tests
SET state=CASE WHEN (SELECT count(id) FROM tests WHERE run_id=? AND testname=? AND item_path != '' AND state in ('RUNNING','NOT_STARTED')) > 0 THEN
'RUNNING'
|
|
|
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
|
(sqlite3:execute
db
"UPDATE tests
SET fail_count=(SELECT count(id) FROM tests WHERE run_id=? AND testname=? AND item_path != '' AND status='FAIL'),
pass_count=(SELECT count(id) FROM tests WHERE run_id=? AND testname=? AND item_path != '' AND (status='PASS' OR status='WARN' OR status='WAIVED'))
WHERE run_id=? AND testname=? AND item_path='';"
run-id test-name run-id test-name run-id test-name)
;; (thread-sleep! 0.1) ;; give other processes a chance here, no, better to be done ASAP?
(if (equal? status "RUNNING") ;; running takes priority over all other states, force the test state to RUNNING
(sqlite3:execute db "UPDATE tests SET state=? WHERE run_id=? AND testname=? AND item_path='';" "RUNNING" run-id test-name)
(sqlite3:execute
db
"UPDATE tests
SET state=CASE WHEN (SELECT count(id) FROM tests WHERE run_id=? AND testname=? AND item_path != '' AND state in ('RUNNING','NOT_STARTED')) > 0 THEN
'RUNNING'
|