summaryrefslogtreecommitdiff
path: root/makima/frontend/src/hooks/useDirectives.ts
diff options
context:
space:
mode:
Diffstat (limited to 'makima/frontend/src/hooks/useDirectives.ts')
-rw-r--r--makima/frontend/src/hooks/useDirectives.ts17
1 files changed, 13 insertions, 4 deletions
diff --git a/makima/frontend/src/hooks/useDirectives.ts b/makima/frontend/src/hooks/useDirectives.ts
index f5f2b36..e67733c 100644
--- a/makima/frontend/src/hooks/useDirectives.ts
+++ b/makima/frontend/src/hooks/useDirectives.ts
@@ -19,6 +19,7 @@ import {
failDirectiveStep,
skipDirectiveStep,
updateDirectiveGoal,
+ cleanupDirectiveTasks,
} from "../lib/api";
export function useDirectives() {
@@ -80,16 +81,18 @@ export function useDirective(id: string | undefined) {
refresh();
}, [refresh]);
- // Auto-poll while directive is active or has an orchestrator task
+ // Auto-poll while directive is active, has an orchestrator task, or has a completion task
useEffect(() => {
if (!directive) return;
const needsPolling =
- directive.status === "active" || directive.orchestratorTaskId != null;
+ directive.status === "active" ||
+ directive.orchestratorTaskId != null ||
+ directive.completionTaskId != null;
if (!needsPolling) return;
const interval = setInterval(refresh, 5000);
return () => clearInterval(interval);
- }, [directive?.status, directive?.orchestratorTaskId, refresh]);
+ }, [directive?.status, directive?.orchestratorTaskId, directive?.completionTaskId, refresh]);
const update = useCallback(async (req: UpdateDirectiveRequest) => {
if (!id) return;
@@ -151,11 +154,17 @@ export function useDirective(id: string | undefined) {
await refresh();
}, [id, refresh]);
+ const cleanupTasks = useCallback(async () => {
+ if (!id) return;
+ await cleanupDirectiveTasks(id);
+ await refresh();
+ }, [id, refresh]);
+
return {
directive, loading, error, refresh,
update, addStep, removeStep,
start, pause, advance,
completeStep, failStep, skipStep,
- updateGoal,
+ updateGoal, cleanupTasks,
};
}