keep job sync on cancel

This commit is contained in:
Guilhem
2025-03-25 13:19:02 +00:00
parent dd3074a23c
commit 5d3459aaf1
2 changed files with 16 additions and 6 deletions
@@ -36,6 +36,7 @@
let testJobLoader: TestJobLoader
let testIsLoading = false
let testJob: Job | undefined = undefined
let cancelLoading = false
let jobProgressReset: () => void
@@ -101,11 +102,17 @@
}
let forceJson = false
// cancelLoading is true when the job is being cancelled
$: if (cancelLoading && !testIsLoading) {
cancelLoading = false
}
</script>
<TestJobLoader
toastError={noEditor}
on:done={() => jobDone()}
on:cancel-loading={({ detail }) => (cancelLoading = detail)}
bind:scriptProgress
bind:this={testJobLoader}
bind:isLoading={testIsLoading}
@@ -121,14 +128,15 @@
<div class="w-full justify-center flex">
{#if testIsLoading}
<Button size="sm" on:click={testJobLoader?.cancelJob} btnClasses="w-full" color="red">
<Button size="sm" on:click={testJobLoader?.cancelJob} btnClasses="w-28" color="red">
<Loader2 size={16} class="animate-spin mr-1" />
Cancel
{cancelLoading ? 'Canceling...' : 'Cancel'}
</Button>
{:else}
<Button
color="dark"
btnClasses="truncate"
btnClasses="truncate w-28"
wrapClasses="w-28"
size="sm"
on:click={() => runTest(stepArgs)}
shortCut={{
@@ -150,8 +150,9 @@
export async function cancelJob() {
const id = currentId
if (id) {
dispatch('cancel', id)
currentId = undefined
// currentId = undefined why do we need this? This leads to not watching the job anymore hence not getting the update of the cancelled job
// dispatch('cancel', id) this event is not used anywhere
dispatch('cancel-loading', true)
try {
await JobService.cancelQueuedJob({
workspace: $workspaceStore ?? '',
@@ -159,6 +160,7 @@
requestBody: {}
})
} catch (err) {
dispatch('cancel-loading', false)
console.error(err)
}
}
@@ -283,7 +285,7 @@
async function syncer(id: string): Promise<void> {
if (currentId != id) {
dispatch('cancel', id)
// dispatch('cancel', id) This event is not used anywhere
return
}
syncIteration++