Skip to content
This repository was archived by the owner on Jul 25, 2025. It is now read-only.

Commit 481af0d

Browse files
author
Nikhil Thorat
authored
1 parent 256c171 commit 481af0d

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

lilac/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def manifest(self) -> TaskManifest:
101101
tasks_with_progress = [
102102
(task.total_progress / task.total_len)
103103
for task in self._task_info.values()
104-
if task.total_progress and task.total_len and task.status != TaskStatus.COMPLETED
104+
if task.total_progress and task.total_len and task.status == TaskStatus.PENDING
105105
]
106106
return TaskManifest(
107107
tasks=self._task_info,

web/blueprint/src/lib/components/TaskStatus.svelte

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script lang="ts">
22
import {queryAuthInfo} from '$lib/queries/serverQueries';
3-
import {queryTaskManifest} from '$lib/queries/taskQueries';
4-
import {Loading, Popover, ProgressBar} from 'carbon-components-svelte';
3+
import {cancelTaskMutation, queryTaskManifest} from '$lib/queries/taskQueries';
4+
import {Loading, Modal, Popover, ProgressBar} from 'carbon-components-svelte';
55
import type {ProgressBarProps} from 'carbon-components-svelte/types/ProgressBar/ProgressBar.svelte';
6+
import {CloseFilled} from 'carbon-icons-svelte';
67
import Checkmark from 'carbon-icons-svelte/lib/Checkmark.svelte';
78
import {hoverTooltip} from './common/HoverTooltip';
89
@@ -21,9 +22,19 @@
2122
const taskToProgressStatus: {[taskStatus: string]: ProgressBarProps['status']} = {
2223
pending: 'active',
2324
completed: 'finished',
24-
error: 'error'
25+
error: 'error',
26+
cancelled: 'error'
2527
};
2628
29+
const cancelTask = cancelTaskMutation();
30+
let cancelTaskId: string | undefined = undefined;
31+
let cancelTaskName: string | undefined = undefined;
32+
function cancelTaskAccepted() {
33+
if (cancelTaskId == null) return;
34+
$cancelTask.mutate([cancelTaskId]);
35+
cancelTaskId = undefined;
36+
}
37+
2738
const authInfo = queryAuthInfo();
2839
$: canRunTasks =
2940
$authInfo.data?.access.dataset.compute_signals || $authInfo.data?.access.create_dataset;
@@ -78,12 +89,22 @@
7889
task.total_progress != null && task.total_len != null
7990
? task.total_progress / task.total_len
8091
: undefined}
81-
{@const message = task.error ?? task.message}
92+
{@const message =
93+
task.status != 'cancelled' ? task.error ?? task.message : 'Task cancelled.'}
8294
<div class="relative border-b-2 border-slate-200 p-4 text-left last:border-b-0">
83-
<div class="text-s flex flex-row">
95+
<div class="text-s flex flex-row items-center">
8496
<div class="mr-2">{task.name}</div>
97+
{#if task.status === 'pending'}
98+
<div use:hoverTooltip={{text: 'Cancel task'}}>
99+
<button
100+
on:click|stopPropagation={() => {
101+
cancelTaskId = id;
102+
cancelTaskName = task.name;
103+
}}><CloseFilled /></button
104+
>
105+
</div>
106+
{/if}
85107
</div>
86-
<button>Cancel button</button>
87108
<div class="progress-container mt-3">
88109
<ProgressBar
89110
labelText={message || ''}
@@ -102,6 +123,25 @@
102123
</div>
103124
{/if}
104125

126+
<Modal
127+
size="xs"
128+
open={cancelTaskId != null}
129+
modalHeading="Cancel task"
130+
primaryButtonText="Confirm"
131+
secondaryButtonText="Cancel"
132+
selectorPrimaryFocus=".bx--btn--primary"
133+
on:submit={() => cancelTaskAccepted()}
134+
on:click:button--secondary={() => {
135+
cancelTaskId = undefined;
136+
}}
137+
on:close={(cancelTaskId = undefined)}
138+
>
139+
<div class="italic">
140+
{cancelTaskName}
141+
</div>
142+
<p class="mt-4">Are you sure you want to cancel this task?</p>
143+
</Modal>
144+
105145
<style lang="postcss">
106146
:global(.progress-container .bx--progress-bar__label) {
107147
@apply text-xs;

web/blueprint/src/lib/queries/taskQueries.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {TasksService} from '$lilac';
2-
import {createApiQuery} from './queryUtils';
2+
import {createApiMutation, createApiQuery} from './queryUtils';
33

44
export const TASKS_TAG = 'tasks';
55

@@ -9,3 +9,5 @@ export const queryTaskManifest = createApiQuery(TasksService.getTaskManifest, TA
99
refetchIntervalInBackground: false,
1010
refetchOnWindowFocus: true
1111
});
12+
13+
export const cancelTaskMutation = createApiMutation(TasksService.cancelTask);

0 commit comments

Comments
 (0)