fix: changing build log without reload

fix: elapsed time of a build
This commit is contained in:
Andras Bacsai 2022-09-15 13:57:20 +02:00
parent 40dfe0919b
commit f09d76da35
5 changed files with 30 additions and 28 deletions

View File

@ -1168,7 +1168,12 @@ export async function getBuildLogs(request: FastifyRequest<GetBuildLogs>) {
skip skip
}); });
} }
builds = builds.map((build) => {
if (build.status === 'running') {
build.elapsed = (day().utc().diff(day(build.createdAt)) / 1000).toFixed(0);
}
return build
})
return { return {
builds, builds,
buildCount buildCount

View File

@ -157,3 +157,5 @@ export const addToast = (toast: AddToast) => {
if (t.timeout) t.timeoutInterval = setTimeout(() => dismissToast(id), t.timeout) if (t.timeout) t.timeoutInterval = setTimeout(() => dismissToast(id), t.timeout)
toasts.update((all: any) => [t, ...all]) toasts.update((all: any) => [t, ...all])
} }
export const selectedBuildId: any = writable(null)

View File

@ -67,7 +67,8 @@
setLocation, setLocation,
addToast, addToast,
isDeploymentEnabled, isDeploymentEnabled,
checkIfDeploymentEnabledApplications checkIfDeploymentEnabledApplications,
selectedBuildId
} from '$lib/store'; } from '$lib/store';
import { errorNotification, handlerNotFoundLoad } from '$lib/common'; import { errorNotification, handlerNotFoundLoad } from '$lib/common';
import Tooltip from '$lib/components/Tooltip.svelte'; import Tooltip from '$lib/components/Tooltip.svelte';
@ -89,13 +90,10 @@
message: $t('application.deployment_queued'), message: $t('application.deployment_queued'),
type: 'success' type: 'success'
}); });
if ($page.url.pathname.startsWith(`/applications/${id}/logs/build`)) { $selectedBuildId = buildId;
return window.location.assign(`/applications/${id}/logs/build?buildId=${buildId}`);
} else {
return await goto(`/applications/${id}/logs/build?buildId=${buildId}`, { return await goto(`/applications/${id}/logs/build?buildId=${buildId}`, {
replaceState: true replaceState: true
}); });
}
} catch (error) { } catch (error) {
return errorNotification(error); return errorNotification(error);
} }

View File

@ -1,6 +1,4 @@
<script lang="ts"> <script lang="ts">
export let buildId: any;
import { createEventDispatcher, onDestroy, onMount } from 'svelte'; import { createEventDispatcher, onDestroy, onMount } from 'svelte';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@ -12,6 +10,8 @@
import { errorNotification } from '$lib/common'; import { errorNotification } from '$lib/common';
import Tooltip from '$lib/components/Tooltip.svelte'; import Tooltip from '$lib/components/Tooltip.svelte';
import { day } from '$lib/dayjs'; import { day } from '$lib/dayjs';
import { selectedBuildId } from '$lib/store';
let logs: any = []; let logs: any = [];
let currentStatus: any; let currentStatus: any;
let streamInterval: any; let streamInterval: any;
@ -42,7 +42,7 @@
logs: responseLogs, logs: responseLogs,
status, status,
fromDb: from fromDb: from
} = await get(`/applications/${id}/logs/build/${buildId}?sequence=${sequence}`); } = await get(`/applications/${id}/logs/build/${$selectedBuildId}?sequence=${sequence}`);
currentStatus = status; currentStatus = status;
logs = logs.concat( logs = logs.concat(
responseLogs.map((log: any) => ({ ...log, line: cleanAnsiCodes(log.line) })) responseLogs.map((log: any) => ({ ...log, line: cleanAnsiCodes(log.line) }))
@ -56,7 +56,7 @@
const nextSequence = logs[logs.length - 1]?.time || 0; const nextSequence = logs[logs.length - 1]?.time || 0;
try { try {
const data = await get( const data = await get(
`/applications/${id}/logs/build/${buildId}?sequence=${nextSequence}` `/applications/${id}/logs/build/${$selectedBuildId}?sequence=${nextSequence}`
); );
status = data.status; status = data.status;
currentStatus = status; currentStatus = status;
@ -78,7 +78,7 @@
try { try {
cancelInprogress = true; cancelInprogress = true;
await post(`/applications/${id}/cancel`, { await post(`/applications/${id}/cancel`, {
buildId, $selectedBuildId,
applicationId: id applicationId: id
}); });
} catch (error) { } catch (error) {

View File

@ -23,7 +23,7 @@
export let application: any; export let application: any;
export let buildCount: any; export let buildCount: any;
import { page } from '$app/stores'; import { page } from '$app/stores';
import { addToast } from '$lib/store'; import { addToast, selectedBuildId } from '$lib/store';
import BuildLog from './_BuildLog.svelte'; import BuildLog from './_BuildLog.svelte';
import { get, post } from '$lib/api'; import { get, post } from '$lib/api';
import { t } from '$lib/translations'; import { t } from '$lib/translations';
@ -34,12 +34,11 @@
const { id } = $page.params; const { id } = $page.params;
let loadBuildLogsInterval: any = null; let loadBuildLogsInterval: any = null;
let buildId: any;
let skip = 0; let skip = 0;
let noMoreBuilds = buildCount < 5 || buildCount <= skip; let noMoreBuilds = buildCount < 5 || buildCount <= skip;
let preselectedBuildId = $page.url.searchParams.get('buildId'); let preselectedBuildId = $page.url.searchParams.get('buildId');
if (preselectedBuildId) buildId = preselectedBuildId; if (preselectedBuildId) $selectedBuildId = preselectedBuildId;
onMount(async () => { onMount(async () => {
getBuildLogs(); getBuildLogs();
@ -92,8 +91,8 @@
} }
} }
function loadBuild(build: any) { function loadBuild(build: any) {
buildId = build; $selectedBuildId = build;
return changeQueryParams(buildId); return changeQueryParams($selectedBuildId);
} }
async function resetQueue() { async function resetQueue() {
const sure = confirm( const sure = confirm(
@ -192,7 +191,7 @@
class:rounded-tr={index === 0} class:rounded-tr={index === 0}
class:rounded-br={index === builds.length - 1} class:rounded-br={index === builds.length - 1}
class="flex cursor-pointer items-center justify-center py-4 no-underline transition-all duration-100 hover:bg-coolgray-300 hover:shadow-xl" class="flex cursor-pointer items-center justify-center py-4 no-underline transition-all duration-100 hover:bg-coolgray-300 hover:shadow-xl"
class:bg-coolgray-200={buildId === build.id} class:bg-coolgray-200={$selectedBuildId === build.id}
> >
<div class="flex-col px-2 text-center min-w-[10rem]"> <div class="flex-col px-2 text-center min-w-[10rem]">
<div class="text-sm font-bold"> <div class="text-sm font-bold">
@ -213,13 +212,11 @@
<div class="w-48 text-center text-xs"> <div class="w-48 text-center text-xs">
{#if build.status === 'running'} {#if build.status === 'running'}
<div> <div>
{day(build.createdAt)}
{day()}
<span class="font-bold text-xl" <span class="font-bold text-xl"
>{(day().utc().diff(day(build.createdAt)) / 1000).toFixed(0)}s</span >{build.elapsed}s</span
> >
</div> </div>
{:else} {:else if build.status !== 'queued'}
<div>{day(build.updatedAt).utc().fromNow()}</div> <div>{day(build.updatedAt).utc().fromNow()}</div>
<div> <div>
{$t('application.build.finished_in')} {$t('application.build.finished_in')}
@ -249,9 +246,9 @@
{/if} {/if}
</div> </div>
<div class="flex-1 md:w-96"> <div class="flex-1 md:w-96">
{#if buildId} {#if $selectedBuildId}
{#key buildId} {#key $selectedBuildId}
<svelte:component this={BuildLog} {buildId} /> <svelte:component this={BuildLog} />
{/key} {/key}
{/if} {/if}
</div> </div>