[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Ludovic Courtès |
Date: |
Fri, 1 Sep 2023 17:43:57 -0400 (EDT) |
branch: wip-actors
commit 6045171904db9e0a9a4ac01a9ecd213067d3fa57
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Sep 1 23:23:32 2023 +0200
http: Send jobset registration requests to the bridge.
* src/cuirass/http.scm (url-handler): Add 'bridge' parameter.
In "/admin/specification/add" route, write to BRIDGE.
(run-cuirass-server): Add #:bridge-socket-file-name. When true, open
connection to the bridge. Pass it to 'url-handler'.
* tests/http.scm ("cuirass-run"): Pass #:bridge-socket-file-name to
'run-cuirass-server'.
---
src/cuirass/http.scm | 78 +++++++++++++++++++++++++++++++---------------------
tests/http.scm | 4 ++-
2 files changed, 50 insertions(+), 32 deletions(-)
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 92d187e..4e2de05 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -508,7 +508,7 @@ passed, only display JOBS targeting this SYSTEM."
;; Time-to-live (in seconds) advertised for files under /static.
(* 12 3600))
-(define (url-handler request body)
+(define (url-handler bridge request body)
(define* (respond response #:key body)
(values response body #f))
@@ -648,10 +648,13 @@ passed, only display JOBS targeting this SYSTEM."
#:code 400)
(begin
(db-add-or-update-specification spec)
- ;; FIXME: Notify the jobset registry in the 'cuirass register'
- ;; process.
- ;;
- ;; (register-jobset jobset-registry spec)
+
+ (when bridge
+ ;; Notify the jobset registry in the 'cuirass register' process.
+ (write `(register-jobset ,(specification-name spec))
+ bridge)
+ (newline bridge))
+
(respond
(build-response #:code 302
#:headers
@@ -1213,34 +1216,47 @@ passed, only display JOBS targeting this SYSTEM."
(_
(respond-not-found (uri->string (request-uri request))))))
-(define* (run-cuirass-server #:key (host "localhost") (port 8080))
+(define* (run-cuirass-server #:key (host "localhost") (port 8080)
+ (bridge-socket-file-name
+ (%bridge-socket-file-name)))
(let* ((host-info (gethostbyname host))
(address (inet-ntop (hostent:addrtype host-info)
(car (hostent:addr-list host-info)))))
(log-info "listening on ~A:~A" address port)
- ;; Here we use our own web backend, call 'fiberized'. We cannot use the
- ;; 'fibers' backend that comes with Fibers 1.0.0 because it does its own
- ;; thread creations and calls 'run-fibers' by itself, which isn't
- ;; necessary here (and harmful).
- ;;
- ;; In addition, we roll our own instead of using Guile's 'run-server' and
- ;; 'serve-one-client'. The key thing here is that we spawn a fiber to
- ;; process each client request and then directly go back waiting for the
- ;; next client (conversely, Guile's 'run-server' loop processes clients
- ;; one after another, sequentially.) We can do that because we don't
- ;; maintain any state across connections.
- ;;
- ;; XXX: We don't do 'call-with-sigint' like 'run-server' does.
- (let* ((impl (lookup-server-impl 'fiberized))
- (server (open-server impl `(#:host ,address #:port ,port))))
- (let loop ()
- (let-values (((client request body)
- (read-client impl server)))
- ;; Spawn a fiber to handle REQUEST and reply to CLIENT.
- (spawn-fiber
- (lambda ()
- (let-values (((response body state)
- (handle-request url-handler request body '())))
- (write-client impl server client response body)))))
- (loop)))))
+ ;; With 'cuirass web' running as a separate process, we need to open a
+ ;; connection over the "bridge" to talk to the 'cuirass register' process.
+ (let ((bridge (and bridge-socket-file-name
+ (socket AF_UNIX
+ (logior SOCK_STREAM SOCK_NONBLOCK SOCK_CLOEXEC)
+ 0))))
+ (when bridge
+ (log-info "connecting to bridge at '~a'" bridge-socket-file-name)
+ (connect bridge AF_UNIX bridge-socket-file-name))
+
+ ;; Here we use our own web backend, call 'fiberized'. We cannot use the
+ ;; 'fibers' backend that comes with Fibers 1.0.0 because it does its own
+ ;; thread creations and calls 'run-fibers' by itself, which isn't
+ ;; necessary here (and harmful).
+ ;;
+ ;; In addition, we roll our own instead of using Guile's 'run-server'
+ ;; and 'serve-one-client'. The key thing here is that we spawn a fiber
+ ;; to process each client request and then directly go back waiting for
+ ;; the next client (conversely, Guile's 'run-server' loop processes
+ ;; clients one after another, sequentially.) We can do that because we
+ ;; don't maintain any state across connections.
+ ;;
+ ;; XXX: We don't do 'call-with-sigint' like 'run-server' does.
+ (let* ((impl (lookup-server-impl 'fiberized))
+ (server (open-server impl `(#:host ,address #:port ,port))))
+ (let loop ()
+ (let-values (((client request body)
+ (read-client impl server)))
+ ;; Spawn a fiber to handle REQUEST and reply to CLIENT.
+ (spawn-fiber
+ (lambda ()
+ (let-values (((response body state)
+ (handle-request (cut url-handler bridge <...>)
+ request body '())))
+ (write-client impl server client response body)))))
+ (loop))))))
diff --git a/tests/http.scm b/tests/http.scm
index fdb0f8a..c73e2b2 100644
--- a/tests/http.scm
+++ b/tests/http.scm
@@ -93,7 +93,9 @@
(lambda ()
(run-fibers
(lambda ()
- (run-cuirass-server #:port 6688))
+ (run-cuirass-server #:port 6688
+ ;; Don't attempt to connect to the bridge.
+ #:bridge-socket-file-name #f))
#:drain? #t))))
(test-assert "wait-server"