52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
;; *transport-type* and *runremote* from the monitor.db
;;
;; client:setup
;;
;; lookup_server, need to remove *runremote* stuff
;;
(define (client:setup run-id #!key (remaining-tries 3))
(let ((hostinfo (and run-id (hash-table-ref/default *runremote* run-id #f))))
(if hostinfo
hostinfo ;; have hostinfo - just return it
(let* ((hostinfo (open-run-close tasks:get-server tasks:open-db run-id)))
(if (not hostinfo)
(if (> remaining-tries 0)
(begin
(server:ensure-running run-id)
(client:setup run-id remaining-tries: (- remaining-tries 1)))
(begin
(debug:print 0 "ERROR: Expected to be able to connect to a server by now. No server available for run-id = " run-id)
(exit 1)))
(begin
(hash-table-set! *runremote* run-id hostinfo)
(debug:print-info 11 "CLIENT SETUP, hostinfo=" hostinfo)
(client:start run-id hostinfo)))))))
(define (client:start run-id server-info)
;; this saves the server-info in the *runremote* hash and returns it
(http-transport:client-connect run-id
(tasks:hostinfo-get-interface server-info)
(tasks:hostinfo-get-port server-info)))
;; client:signal-handler
(define (client:signal-handler signum)
(handle-exceptions
|
>
>
>
>
|
|
>
|
<
|
|
>
>
>
>
>
>
|
>
>
|
<
>
|
>
>
|
>
|
|
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
<
|
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
;; *transport-type* and *runremote* from the monitor.db
;;
;; client:setup
;;
;; lookup_server, need to remove *runremote* stuff
;;
(define (client:setup run-id #!key (remaining-tries 3))
(if (<= remaining-tries 0)
(begin
(debug:print 0 "ERROR: failed to start or connect to server for run-id " run-id)
(exit 1))
(let ((server-dat (and run-id (hash-table-ref/default *runremote* run-id #f))))
(if server-dat
(let ((start-res (http-transport:client-connect run-id
(tasks:hostinfo-get-interface server-dat)
(tasks:hostinfo-get-port server-dat))))
(if start-res ;; sucessful login?
(begin
(hash-table-set! *runremote* run-id server-dat)
server-dat)
(begin ;; login failed
(hash-table-delete! *runremote* run-id)
(open-run-close tasks:server-force-clean-run-record
tasks:open-db
run-id
(tasks:hostinfo-get-interface server-dat)
(tasks:hostinfo-get-port server-dat))
(client:setup run-id remaining-tries: (- remaining-tries 1)))))
(let* ((server-dat (open-run-close tasks:get-server tasks:open-db run-id)))
(if server-dat
(let ((start-res (http-transport:client-connect run-id
(tasks:hostinfo-get-interface server-dat)
(tasks:hostinfo-get-port server-dat))))
(if start-res
(begin
(hash-table-set! *runremote* run-id server-dat)
server-dat)
(begin ;; login failed
(hash-table-delete! *runremote* run-id)
(open-run-close tasks:server-force-clean-run-record
tasks:open-db
run-id
(tasks:hostinfo-get-interface server-dat)
(tasks:hostinfo-get-port server-dat))
(server:try-running run-id)
(thread-sleep! 3) ;; give server a little time to start up
(client:setup run-id remaining-tries: (- remaining-tries 1)))))
(begin ;; no server registered
(server:try-running run-id)
(thread-sleep! 3) ;; give server a little time to start up
(client:setup run-id remaining-tries: (- remaining-tries 1)))))))))
;; keep this as a function to ease future
(define (client:start run-id server-info)
(http-transport:client-connect run-id
(tasks:hostinfo-get-interface server-info)
(tasks:hostinfo-get-port server-info)))
;; client:signal-handler
(define (client:signal-handler signum)
(handle-exceptions
|