From c8c34f8ee3a62ab3d86a65bae2a4ddafd619088f Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 23 Oct 2019 15:37:15 +0200 Subject: http: Serve evaluation logs at /eval/ID/log/raw. * src/cuirass/base.scm (evaluation-log-file): Export. * src/cuirass/http.scm (url-handler)[respond-gzipped-file]: New procedure. Add handler for /eval/ID/log/raw. --- src/cuirass/base.scm | 2 ++ src/cuirass/http.scm | 15 +++++++++++++++ 2 files changed, 17 insertions(+) (limited to 'src') diff --git a/src/cuirass/base.scm b/src/cuirass/base.scm index 3dbc5f4..c1e6383 100644 --- a/src/cuirass/base.scm +++ b/src/cuirass/base.scm @@ -63,6 +63,8 @@ build-packages prepare-git process-specs + evaluation-log-file + ;; Parameters. %package-cachedir %gc-root-directory diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm index b6a4358..9f5fdce 100644 --- a/src/cuirass/http.scm +++ b/src/cuirass/http.scm @@ -24,6 +24,7 @@ (define-module (cuirass http) #:use-module (cuirass config) #:use-module (cuirass database) + #:use-module ((cuirass base) #:select (evaluation-log-file)) #:use-module (cuirass utils) #:use-module (cuirass logging) #:use-module (srfi srfi-1) @@ -211,6 +212,14 @@ Hydra format." #:body (call-with-input-file file-path get-bytevector-all)) (respond-not-found file-name)))) + (define (respond-gzipped-file file) + ;; Return FILE with 'gzip' content-encoding. + (respond `((content-type . (text/plain (charset . "UTF-8"))) + (content-encoding . (gzip))) + ;; FIXME: FILE is potentially big so it'd be better to not load + ;; it in memory and instead 'sendfile' it. + #:body (call-with-input-file file get-bytevector-all))) + (define (respond-build-not-found build-id) (respond-json-with-error 404 @@ -438,6 +447,12 @@ Hydra format." (#:link . ,(string-append "/eval/" id))))))) (respond-html-eval-not-found id)))) + (("eval" (= string->number id) "log" "raw") + (let ((log (and id (evaluation-log-file id)))) + (if (and log (file-exists? log)) + (respond-gzipped-file log) + (respond-not-found (uri->string (request-uri request)))))) + (("search") (let* ((params (request-parameters request)) (query (and=> (assq-ref params 'query) uri-decode)) -- cgit v1.2.3