| |
| |
| |
| |
|
|
| import { showSystemNotification } from "@/UI/MessageAlerts/SystemNotifications"; |
| import { IJobStatusInfo, JobStatus } from "./QueueTypes"; |
| import { appName } from "@/Core/GlobalVars"; |
| import { capitalize } from "@/Core/Utils/StringUtils"; |
| interface IQueueStore { |
| running: IJobStatusInfo[]; |
| done: IJobStatusInfo[]; |
| } |
|
|
| const queueStore: IQueueStore = { |
| running: [], |
| done: [], |
| }; |
|
|
| |
| |
| |
| |
| |
| export function getQueueStore(): IQueueStore { |
| |
| return JSON.parse(JSON.stringify(queueStore)); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function startInQueueStore( |
| id: string, |
| nprocs: number, |
| cancelFunc: () => void |
| ) { |
| queueStore.running.push({ |
| id: id, |
| progress: 0, |
| numProcessors: nprocs, |
| startTime: Date.now() + Math.random(), |
| endTime: undefined, |
| status: JobStatus.Running, |
| cancelFunc: cancelFunc, |
| } as IJobStatusInfo); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function updateProgressInQueueStore(id: string, progress: number) { |
| if (id === undefined) { |
| return; |
| } |
| const item = queueStore.running.find((item) => item.id === id); |
| if (item) { |
| item.progress = progress; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| function _moveToDoneInQueueStore(id: string, status: JobStatus) { |
| const item = queueStore.running.find((item) => item.id === id); |
| if (item) { |
| item.endTime = Date.now(); |
| item.status = status; |
| queueStore.done.push(item); |
| queueStore.running = queueStore.running.filter( |
| (item) => item.id !== id |
| ); |
| |
| if (!document.hasFocus()) { |
| const jobType = item.id.split("-")[0]; |
| const statusText = |
| status === JobStatus.Done ? "finished" : "cancelled"; |
| const title = `${appName} Job Done: ${capitalize(jobType)}`; |
| const body = `The "${jobType}" job has ${statusText}.`; |
| showSystemNotification(title, body); |
| } |
| } |
| } |
| |
| |
| |
| |
| |
| export function doneInQueueStore(id: string) { |
| if (id !== undefined) { |
| _moveToDoneInQueueStore(id, JobStatus.Done); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| export function cancelInQueueStore(id: string) { |
| |
| const item = queueStore.running.find((item) => item.id === id); |
| if (item) { |
| item.cancelFunc(); |
| } |
|
|
| _moveToDoneInQueueStore(id, JobStatus.Cancelled); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| export function makeUniqJobId(id: string) { |
| return id + "-" + Math.round(Math.random() * 1000000).toString(); |
| } |
|
|