From ad49ce171d7d616f919cda654411fe8247f863fe Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Mon, 11 Mar 2024 02:02:56 +0100 Subject: [PATCH] feat: new deploy queue with live job logs --- src/client/JobLogs.jsx | 26 +++ src/client/JobsPage.jsx | 84 +++------ src/deploys.ts | 76 ++++---- src/jobs.ts | 291 +++++++++++++++++++++++++++++- src/lib/utils.ts | 45 +++++ src/pages/api/jobs.ts | 23 --- src/pages/api/sse.ts | 39 ---- src/pages/api/webhook.ts | 4 +- src/pages/error.astro | 12 ++ src/pages/jobs/[uuid]/index.astro | 35 ++++ src/pages/jobs/[uuid]/logs.ts | 35 ++++ src/pages/jobs/index.astro | 57 +++++- src/runners.ts | 45 +++-- src/styles/main.scss | 27 +++ 14 files changed, 623 insertions(+), 176 deletions(-) create mode 100644 src/client/JobLogs.jsx delete mode 100644 src/pages/api/jobs.ts delete mode 100644 src/pages/api/sse.ts create mode 100644 src/pages/error.astro create mode 100644 src/pages/jobs/[uuid]/index.astro create mode 100644 src/pages/jobs/[uuid]/logs.ts diff --git a/src/client/JobLogs.jsx b/src/client/JobLogs.jsx new file mode 100644 index 0000000..f88dbe2 --- /dev/null +++ b/src/client/JobLogs.jsx @@ -0,0 +1,26 @@ +import { useEffect, useState } from "preact/hooks" + +export const JobLogs = ({}) => { + const [logLines, setLogLines] = useState([]) + + useEffect(async () => { + const res = await fetch(location.href + '/logs?format=raw') + const rawLogs = (await res.text()).trim() + + if (rawLogs.length > 0) setLogLines(rawLogs.split('\n')) + + // Setup SSE + const es = new EventSource(location.href + '/logs?format=sse') + es.addEventListener('message', ({ data }) => { + const event = JSON.parse(data) + setLogLines(lines => [ + ...lines, + event.content, + ]) + }) + }, []) + + return ( +
{logLines.join('\n')}
+ ) +} diff --git a/src/client/JobsPage.jsx b/src/client/JobsPage.jsx index 059b36a..ec1b0a8 100644 --- a/src/client/JobsPage.jsx +++ b/src/client/JobsPage.jsx @@ -6,8 +6,8 @@ import { durationToString } from './lib/utils' /** * @param {import('@/jobs.ts').QueuedJob} props */ -export const QueuedJob = ({ uuid, name, submitter, submittedAt }) => ( -
+export const QueuedJob = ({ uuid, status, name, submitter, submittedAt }) => ( +
(location.href = `/jobs/${uuid}`)}>
{name}