web: core system for queue & queen bee, move remux to new system
it's 3 am and i think i had a divine intervention
This commit is contained in:
40
web/src/lib/state/queen-bee/current-tasks.ts
Normal file
40
web/src/lib/state/queen-bee/current-tasks.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { readable, type Updater } from "svelte/store";
|
||||
|
||||
import type { CobaltWorkerProgress } from "$lib/types/workers";
|
||||
import type { CobaltCurrentTasks, CobaltCurrentTaskItem } from "$lib/types/queen-bee";
|
||||
|
||||
let update: (_: Updater<CobaltCurrentTasks>) => void;
|
||||
|
||||
const currentTasks = readable<CobaltCurrentTasks>(
|
||||
{},
|
||||
(_, _update) => { update = _update }
|
||||
);
|
||||
|
||||
export function addWorkerToQueue(item: CobaltCurrentTaskItem) {
|
||||
update(tasks => {
|
||||
tasks[item.id] = item;
|
||||
return tasks;
|
||||
});
|
||||
}
|
||||
|
||||
export function removeWorkerFromQueue(id: string) {
|
||||
update(tasks => {
|
||||
delete tasks[id];
|
||||
return tasks;
|
||||
});
|
||||
}
|
||||
|
||||
export function updateWorkerProgress(id: string, progress: CobaltWorkerProgress) {
|
||||
update(tasks => {
|
||||
tasks[id].progress = progress;
|
||||
return tasks;
|
||||
});
|
||||
}
|
||||
|
||||
export function clearQueue() {
|
||||
update(() => {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
export { currentTasks };
|
||||
Reference in New Issue
Block a user