diff --git a/apps/task-poster/src/fetcher.ts b/apps/task-poster/src/fetcher.ts index 22f1e3bc..bd2e85d1 100644 --- a/apps/task-poster/src/fetcher.ts +++ b/apps/task-poster/src/fetcher.ts @@ -123,6 +123,9 @@ export const fetcherForm = async ( dsId: number, values: FormValues, msg = "", f: Fetcher | undefined = undefined) => `
+
+ ${msg ? `

${msg}

` : ""} +
step info @@ -185,15 +188,21 @@ export const fetcherForm = async ( )} - +
+ +
+ Comma separated list of capabilities required for tasks (note: only 1 capability is used at the moment). { break; } + // we cap the maximum price of a task to 10* the default price, to + // avoid expensive mistakes. + const maxPrice = BigInt(fetcher.price) * BigInt(10); + const tasks = data.map( - (d, _idx) => - ({ + (d, _idx) => { + const rawPrice = d["dataffect/reward"] ? + BigInt(d["dataffect/reward"] as string) : BigInt(fetcher.price); + const price = rawPrice > maxPrice ? maxPrice : rawPrice; + + return { id: ulid(), title: fetcher.name, - reward: BigInt(fetcher.price * 1000000), + reward: price, timeLimitSeconds: 600, templateId: fetcher.template, templateData: JSON.stringify(d), capability: fetcher.capabilities[0], - }) as Task, + } as Task; + }, ); return tasks; }; -export const getPendingTasks = async (f: Fetcher) => { +export const getPendingTasks = async (f: Fetcher, queueName: string = "queue") => { const tasks = await db.listAll( - ["fetcher", f.datasetId, f.index, "queue", {}], f.batchSize, false + ["fetcher", f.datasetId, f.index, queueName, {}], f.batchSize, false ); return tasks.map(t => t.key[4]); @@ -642,15 +660,19 @@ export const importTasks = async (f: Fetcher) => { await delay(400); const task = await db.get(["task", taskId]); + if (!task) { + console.error(`Queued task not found in db ${taskId}, skipping.`); + continue; + } try { - // TODO: actualize some of the data from the fetcher (like prize - // and templateId. these should probably not be stored to begin - // with, to avoid confusion. + // actualize some of the data from the fetcher (like the + // templateId). these should probably not be stored in the task + // to begin with, to avoid confusion. const serializedTask = { ...task!.data, // convert bigint to string for serialization - reward: BigInt(f.price * 1000000).toString(), + reward: task!.data.reward.toString(), templateId: f.template, }; @@ -782,7 +804,7 @@ const formValidations: ValidationMap = { ? "Must be a number" : num <= 0 ? "Price must be greater than 0" - : num > 100 && "Price too large"; + : num > 100000000 && "Price too large"; }, template: (v: string) => (!v || v.length === 0) && "Template is required", @@ -837,7 +859,7 @@ export const addFetcherRoutes = (app: Express): void => { } else { msg = '

Could not create dataset:

' + msg; console.log(`Invalid form submission ${msg}`); - res.send(await fetcherForm(id, req.body, msg)); + res.send(await fetcherForm(id, req.body, msg, f)); } }); @@ -1168,7 +1190,8 @@ ${Object.entries(peers) id="templateFrame" height="450px" width="100%" - srcdoc="${escapeHTML(renderedTemplate)}">`)); + srcdoc="${escapeHTML(renderedTemplate)}"> +
${JSON.stringify(task, (_, v) => typeof v === 'bigint' ? v.toString() : v)}
`)); }); app.get("/d/:id/pipeline-preview", async (req, res) => {