jbilcke-hf's picture
jbilcke-hf HF staff
working on the VideoChain queue system
652f343
raw
history blame
698 Bytes
import path from "node:path"
import { completedTasksDirFilePath, pendingTasksDirFilePath } from "./constants.mts"
import { readTask } from "./readTask.mts"
export const getTask = async (id: string) => {
const taskFileName = `${id}.json`
const completedTaskFilePath = path.join(completedTasksDirFilePath, taskFileName)
const pendingTaskFilePath = path.join(pendingTasksDirFilePath, taskFileName)
try {
const completedTask = await readTask(completedTaskFilePath)
return completedTask
} catch (err) {
try {
const pendingTask = await readTask(pendingTaskFilePath)
return pendingTask
} catch (err) {
throw new Error(`couldn't find task ${id}`)
}
}
}