104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
(debug:print-info 11 "server-deregister " hostname ", pullport " pullport ", pid " pid)
(if pid
(case action
((delete)(sqlite3:execute mdb "DELETE FROM servers WHERE pid=?;" pid))
(else (sqlite3:execute mdb "UPDATE servers SET state='dead' WHERE pid=?;" pid)))
(if pullport
(case action
((delete)(sqlite3:execute mdb "DELETE FROM servers WHERE hostname=? AND port=?;" hostname port))
(else (sqlite3:execute mdb "UPDATE servers SET state='dead' WHERE hostname=? AND pullport=?;" hostname pullport)))
(debug:print 0 "ERROR: tasks:server-deregister called with neither pid nor port specified"))))
(define (tasks:server-deregister-self mdb hostname)
(tasks:server-deregister mdb hostname pid: (current-process-id)))
(define (tasks:server-get-server-id mdb hostname pullport pid)
|
|
|
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
(debug:print-info 11 "server-deregister " hostname ", pullport " pullport ", pid " pid)
(if pid
(case action
((delete)(sqlite3:execute mdb "DELETE FROM servers WHERE pid=?;" pid))
(else (sqlite3:execute mdb "UPDATE servers SET state='dead' WHERE pid=?;" pid)))
(if pullport
(case action
((delete)(sqlite3:execute mdb "DELETE FROM servers WHERE hostname=? AND pullport=?;" hostname port))
(else (sqlite3:execute mdb "UPDATE servers SET state='dead' WHERE hostname=? AND pullport=?;" hostname pullport)))
(debug:print 0 "ERROR: tasks:server-deregister called with neither pid nor port specified"))))
(define (tasks:server-deregister-self mdb hostname)
(tasks:server-deregister mdb hostname pid: (current-process-id)))
(define (tasks:server-get-server-id mdb hostname pullport pid)
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
(let ((res '())
(best #f))
(sqlite3:for-each-row
(lambda (id hostname interface pullport pubport pid)
(set! res (cons (list hostname interface pullport pubport pid) res))
(debug:print-info 2 "Found existing server " hostname ":" pullport " registered in db"))
mdb
"SELECT id,hostname,interface,pullport,pubport,pid FROM servers WHERE state='live' AND mt_version=? ORDER BY start_time ASC LIMIT 1;" megatest-version)
;; (print "res=" res)
(if (null? res) #f
(let loop ((hed (car res))
(tal (cdr res)))
;; (print "hed=" hed ", tal=" tal)
(let* ((host (list-ref hed 0))
(iface (list-ref hed 1))
(pullport (list-ref hed 2))
(pubport (list-ref hed 3))
(pid (list-ref hed 4))
(alive (open-run-close tasks:server-alive? tasks:open-db #f hostname: host pullport: pullport)))
(if alive
(begin
(debug:print-info 2 "Found an existing, alive, server " host ", " pullport " and " pubport ".")
(list host iface pullport pubport))
(begin
(debug:print-info 1 "Marking " host ":" pullport " as dead in server registry.")
(if port
(open-run-close tasks:server-deregister tasks:open-db host pullport: pullport)
(open-run-close tasks:server-deregister tasks:open-db host pid: pid))
(if (null? tal)
#f
(loop (car tal)(cdr tal))))))))))
(define (tasks:mark-server hostname pullport pid state)
|
|
|
>
|
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
(let ((res '())
(best #f))
(sqlite3:for-each-row
(lambda (id hostname interface pullport pubport pid)
(set! res (cons (list hostname interface pullport pubport pid) res))
(debug:print-info 2 "Found existing server " hostname ":" pullport " registered in db"))
mdb
"SELECT id,hostname,interface,pullport,pubport,pid FROM servers
WHERE strftime('%s','now')-heartbeat < 10
AND mt_version=? ORDER BY start_time ASC LIMIT 1;" megatest-version)
(if (null? res) #f
(let loop ((hed (car res))
(tal (cdr res)))
;; (print "hed=" hed ", tal=" tal)
(let* ((host (list-ref hed 0))
(iface (list-ref hed 1))
(pullport (list-ref hed 2))
(pubport (list-ref hed 3))
(pid (list-ref hed 4))
(alive (open-run-close tasks:server-alive? tasks:open-db #f hostname: host pullport: pullport)))
(if alive
(begin
(debug:print-info 2 "Found an existing, alive, server " host ", " pullport " and " pubport ".")
(list host iface pullport pubport))
(begin
(debug:print-info 1 "Marking " host ":" pullport " as dead in server registry.")
(if pullport
(open-run-close tasks:server-deregister tasks:open-db host pullport: pullport)
(open-run-close tasks:server-deregister tasks:open-db host pid: pid))
(if (null? tal)
#f
(loop (car tal)(cdr tal))))))))))
(define (tasks:mark-server hostname pullport pid state)
|