mirror of
https://github.com/imputnet/cobalt.git
synced 2025-06-28 09:28:29 +00:00
web/queue: make completedWorkers into set, require pipelineResults
This commit is contained in:
parent
d78ae8124f
commit
53ca7700a5
@ -40,7 +40,7 @@
|
|||||||
return 100;
|
return 100;
|
||||||
} else if (item.state === "running") {
|
} else if (item.state === "running") {
|
||||||
return totalItemProgress(
|
return totalItemProgress(
|
||||||
item.completedWorkers?.length || 0,
|
item.completedWorkers.size,
|
||||||
$currentTasks[item.runningWorker]?.progress?.percentage || 0,
|
$currentTasks[item.runningWorker]?.progress?.percentage || 0,
|
||||||
item.pipeline.length || 0
|
item.pipeline.length || 0
|
||||||
);
|
);
|
||||||
|
@ -78,7 +78,7 @@
|
|||||||
const starting = $t(`queue.state.starting.${runningWorker.type}`);
|
const starting = $t(`queue.state.starting.${runningWorker.type}`);
|
||||||
|
|
||||||
if (info.pipeline.length > 1) {
|
if (info.pipeline.length > 1) {
|
||||||
const currentPipeline = (info.completedWorkers?.length || 0) + 1;
|
const currentPipeline = info.completedWorkers.size + 1;
|
||||||
return `${starting} (${currentPipeline}/${info.pipeline.length})`;
|
return `${starting} (${currentPipeline}/${info.pipeline.length})`;
|
||||||
}
|
}
|
||||||
return starting;
|
return starting;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
export let percentage: number = 0;
|
export let percentage: number = 0;
|
||||||
export let workerId: string;
|
export let workerId: string;
|
||||||
export let runningWorkerId: string | undefined;
|
export let runningWorkerId: string | undefined;
|
||||||
export let completedWorkers: string[] = [];
|
export let completedWorkers: Set<string>;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="file-progress">
|
<div class="file-progress">
|
||||||
@ -13,7 +13,7 @@
|
|||||||
class="progress"
|
class="progress"
|
||||||
style="width: {Math.min(100, percentage || 0)}%"
|
style="width: {Math.min(100, percentage || 0)}%"
|
||||||
></div>
|
></div>
|
||||||
{:else if completedWorkers?.includes(workerId)}
|
{:else if completedWorkers.has(workerId)}
|
||||||
<div
|
<div
|
||||||
class="progress"
|
class="progress"
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
|
@ -24,7 +24,7 @@ export const startWorker = async ({ worker, workerId, parentId, workerArgs }: Co
|
|||||||
|
|
||||||
if (files?.length === 0) {
|
if (files?.length === 0) {
|
||||||
const parent = get(queue)[parentId];
|
const parent = get(queue)[parentId];
|
||||||
if (parent.state === "running" && parent.pipelineResults) {
|
if (parent.state === "running" && parent.pipelineResults.length) {
|
||||||
files = parent.pipelineResults;
|
files = parent.pipelineResults;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,15 +29,17 @@ export const checkTasks = () => {
|
|||||||
const task = queueItems[item];
|
const task = queueItems[item];
|
||||||
|
|
||||||
if (task.state === "running") {
|
if (task.state === "running") {
|
||||||
// if the running worker isn't completed and wait to be called again
|
// if the running worker isn't completed, wait
|
||||||
// (on worker completion)
|
// to be called again on worker completion
|
||||||
if (!task.completedWorkers?.includes(task.runningWorker)) {
|
if (!task.completedWorkers.has(task.runningWorker)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if all workers are completed, then return the final file and go to next task
|
// if all workers are completed, then return the
|
||||||
if (task.completedWorkers.length === task.pipeline.length) {
|
// the final file and go to the next task
|
||||||
const finalFile = task.pipelineResults?.pop();
|
if (task.completedWorkers.size === task.pipeline.length) {
|
||||||
|
const finalFile = task.pipelineResults.pop();
|
||||||
|
|
||||||
if (finalFile) {
|
if (finalFile) {
|
||||||
itemDone(task.id, finalFile);
|
itemDone(task.id, finalFile);
|
||||||
continue;
|
continue;
|
||||||
@ -49,9 +51,9 @@ export const checkTasks = () => {
|
|||||||
|
|
||||||
// if current worker is completed, but there are more workers,
|
// if current worker is completed, but there are more workers,
|
||||||
// then start the next one and wait to be called again
|
// then start the next one and wait to be called again
|
||||||
for (let i = 0; i < task.pipeline.length; i++) {
|
for (const worker of task.pipeline) {
|
||||||
if (!task.completedWorkers.includes(task.pipeline[i].workerId)) {
|
if (!task.completedWorkers.has(worker.workerId)) {
|
||||||
startPipeline(task.pipeline[i]);
|
startPipeline(worker);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import { clearFileStorage, removeFromFileStorage } from "$lib/storage";
|
|||||||
import { clearCurrentTasks, removeWorkerFromQueue } from "$lib/state/queen-bee/current-tasks";
|
import { clearCurrentTasks, removeWorkerFromQueue } from "$lib/state/queen-bee/current-tasks";
|
||||||
|
|
||||||
import type { CobaltFileReference } from "$lib/types/storage";
|
import type { CobaltFileReference } from "$lib/types/storage";
|
||||||
import type { CobaltQueue, CobaltQueueItem } from "$lib/types/queue";
|
import type { CobaltQueue, CobaltQueueItem, CobaltQueueItemRunning } from "$lib/types/queue";
|
||||||
|
|
||||||
const clearPipelineCache = (queueItem: CobaltQueueItem) => {
|
const clearPipelineCache = (queueItem: CobaltQueueItem) => {
|
||||||
if (queueItem.state === "running" && queueItem.pipelineResults) {
|
if (queueItem.state === "running" && queueItem.pipelineResults) {
|
||||||
@ -74,10 +74,13 @@ export function itemDone(id: string, file: CobaltFileReference) {
|
|||||||
|
|
||||||
export function pipelineTaskDone(id: string, workerId: string, file: CobaltFileReference) {
|
export function pipelineTaskDone(id: string, workerId: string, file: CobaltFileReference) {
|
||||||
update(queueData => {
|
update(queueData => {
|
||||||
if (queueData[id] && queueData[id].state === "running") {
|
const item = queueData[id];
|
||||||
queueData[id].pipelineResults = [...queueData[id].pipelineResults || [], file];
|
|
||||||
queueData[id].completedWorkers = [...queueData[id].completedWorkers || [], workerId];
|
if (item && item.state === 'running') {
|
||||||
|
item.pipelineResults.push(file);
|
||||||
|
item.completedWorkers.add(workerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return queueData;
|
return queueData;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -87,13 +90,15 @@ export function pipelineTaskDone(id: string, workerId: string, file: CobaltFileR
|
|||||||
|
|
||||||
export function itemRunning(id: string, workerId: string) {
|
export function itemRunning(id: string, workerId: string) {
|
||||||
update(queueData => {
|
update(queueData => {
|
||||||
if (queueData[id]) {
|
const data = queueData[id] as CobaltQueueItemRunning;
|
||||||
queueData[id] = {
|
|
||||||
...queueData[id],
|
if (data) {
|
||||||
state: "running",
|
data.state = 'running';
|
||||||
runningWorker: workerId,
|
data.runningWorker = workerId;
|
||||||
}
|
data.completedWorkers ??= new Set();
|
||||||
|
data.pipelineResults ??= [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return queueData;
|
return queueData;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ export type CobaltQueueItemWaiting = CobaltQueueBaseItem & {
|
|||||||
export type CobaltQueueItemRunning = CobaltQueueBaseItem & {
|
export type CobaltQueueItemRunning = CobaltQueueBaseItem & {
|
||||||
state: "running",
|
state: "running",
|
||||||
runningWorker: string,
|
runningWorker: string,
|
||||||
completedWorkers?: string[],
|
completedWorkers: Set<string>,
|
||||||
pipelineResults?: CobaltFileReference[],
|
pipelineResults: CobaltFileReference[],
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CobaltQueueItemDone = CobaltQueueBaseItem & {
|
export type CobaltQueueItemDone = CobaltQueueBaseItem & {
|
||||||
|
Loading…
Reference in New Issue
Block a user