fix: Cancel
This commit is contained in:
@@ -3,21 +3,19 @@ import { buildQueue } from '$lib/queues';
|
|||||||
import type { RequestHandler } from '@sveltejs/kit';
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
import * as db from '$lib/database';
|
import * as db from '$lib/database';
|
||||||
|
|
||||||
export const post: RequestHandler = async (event) => {
|
async function cleanupDB(buildId: string) {
|
||||||
const { buildId, applicationId } = await event.request.json();
|
const data = await db.prisma.build.findUnique({ where: { id: buildId } });
|
||||||
if (!buildId) {
|
if (data?.status === 'queued' || data?.status === 'running') {
|
||||||
return {
|
await db.prisma.build.update({ where: { id: buildId }, data: { status: 'failed' } });
|
||||||
status: 500,
|
|
||||||
body: {
|
|
||||||
message: 'Build ID not found.'
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
|
||||||
try {
|
async function stopBuild(buildId, applicationId) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
await new Promise<void>(async (resolve, reject) => {
|
await new Promise<void>(async (resolve, reject) => {
|
||||||
const job = await buildQueue.getJob(buildId);
|
const job = await buildQueue.getJob(buildId);
|
||||||
if (!job) {
|
if (!job) {
|
||||||
|
await cleanupDB(buildId);
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
const {
|
const {
|
||||||
@@ -31,9 +29,9 @@ export const post: RequestHandler = async (event) => {
|
|||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
if (count > 60) {
|
if (count > 100) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
reject(new Error('Could not cancel build.'));
|
return resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { stdout: buildContainers } = await asyncExecShell(
|
const { stdout: buildContainers } = await asyncExecShell(
|
||||||
@@ -57,14 +55,22 @@ export const post: RequestHandler = async (event) => {
|
|||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
}, 1000);
|
}, 100);
|
||||||
|
|
||||||
resolve();
|
|
||||||
});
|
});
|
||||||
const data = await db.prisma.build.findUnique({ where: { id: buildId } });
|
}
|
||||||
if (data?.status === 'queued' || data?.status === 'running') {
|
export const post: RequestHandler = async (event) => {
|
||||||
await db.prisma.build.update({ where: { id: buildId }, data: { status: 'failed' } });
|
const { buildId, applicationId } = await event.request.json();
|
||||||
|
if (!buildId) {
|
||||||
|
return {
|
||||||
|
status: 500,
|
||||||
|
body: {
|
||||||
|
message: 'Build ID not found.'
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await stopBuild(buildId, applicationId);
|
||||||
|
await cleanupDB(buildId);
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: {
|
body: {
|
||||||
|
@@ -129,9 +129,13 @@
|
|||||||
{#if currentStatus === 'running'}
|
{#if currentStatus === 'running'}
|
||||||
<button
|
<button
|
||||||
on:click={cancelBuild}
|
on:click={cancelBuild}
|
||||||
|
class:animation-spin={cancelInprogress}
|
||||||
class="bg-transparent hover:text-red-500 hover:bg-coolgray-500"
|
class="bg-transparent hover:text-red-500 hover:bg-coolgray-500"
|
||||||
data-tooltip="Cancel build"
|
data-tooltip="Cancel build"
|
||||||
>
|
>
|
||||||
|
{#if cancelInprogress}
|
||||||
|
Cancelling...
|
||||||
|
{:else}
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
class="w-6 h-6"
|
class="w-6 h-6"
|
||||||
@@ -146,6 +150,7 @@
|
|||||||
<circle cx="12" cy="12" r="9" />
|
<circle cx="12" cy="12" r="9" />
|
||||||
<path d="M10 10l4 4m0 -4l-4 4" />
|
<path d="M10 10l4 4m0 -4l-4 4" />
|
||||||
</svg>
|
</svg>
|
||||||
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user