Handle eof when reading logs

This commit is contained in:
Christopher Baines 2023-11-05 18:49:11 +00:00
parent b026b8795b
commit 341eb4a283
1 changed files with 23 additions and 20 deletions

View File

@ -72,33 +72,36 @@ VALUES (nextval('" (log-part-sequence-name job_id) "'), $1, $2)")
(list job-id))
(let loop ((line (get-line port-to-read-from)))
(let ((line-with-newline
(string-append line "\n")))
(catch #t
(lambda ()
(insert logging-conn job-id line-with-newline)
(display line-with-newline))
(lambda (key . args)
(display
(simple-format
#f
"
error: ~A: ~A
error: could not insert log part: '~A'\n\n"
key args line))
(if (eof-object? line)
(simple-format #t "finished reading logs for ~A\n"
job-id)
(let ((line-with-newline
(string-append line "\n")))
(catch #t
(lambda ()
(insert
logging-conn
job-id
(insert logging-conn job-id line-with-newline)
(display line-with-newline))
(lambda (key . args)
(display
(simple-format
#f
"
error: ~A: ~A
error: could not insert log part: '~A'\n\n"
key args line))
(catch #t
(lambda ()
(insert
logging-conn
job-id
(simple-format
#f
"
guix-data-service: error: missing log line: ~A
\n" key)))
(lambda _
#t)))))
(loop (get-line port-to-read-from)))))))
(lambda _
#t))))
(loop (get-line port-to-read-from)))))))))
port-to-write-to)))