620b83832b
* Implement manually invokable jobs through the invokeTrigger Also implemented a job run notification system, that will POST details of a run on completion. This combines with the task callbackUrl system to implement the invokeAndWait * Document the invoke trigger * batch invoke and wait * background fetch timeouts * Use @whatwg-node/fetch instead of the polyfilled fetch * Fix some outdated dependencies in webapp * Improved subtask error propogation messages * Document the OpenAI changes and the batch invoke stuff * Fix dequeuing jobs * Don’t retry the OpenAI completion background task * Added OpenAI changesets * Use the new ResumeTaskService in ProcessCallbackTimeout as well
74 lines
1.7 KiB
TypeScript
74 lines
1.7 KiB
TypeScript
import { $transaction, PrismaClient, PrismaClientOrTransaction, prisma } from "~/db.server";
|
|
import { logger } from "../logger.server";
|
|
import { ResumeTaskService } from "./resumeTask.server";
|
|
|
|
type FoundTask = Awaited<ReturnType<typeof findTask>>;
|
|
|
|
export class ProcessCallbackTimeoutService {
|
|
#prismaClient: PrismaClient;
|
|
|
|
constructor(prismaClient: PrismaClient = prisma) {
|
|
this.#prismaClient = prismaClient;
|
|
}
|
|
|
|
public async call(id: string) {
|
|
const task = await findTask(this.#prismaClient, id);
|
|
|
|
if (!task) {
|
|
return;
|
|
}
|
|
|
|
if (task.status !== "WAITING" || !task.callbackUrl) {
|
|
return;
|
|
}
|
|
|
|
logger.debug("ProcessCallbackTimeoutService.call", { task });
|
|
|
|
return await this.#failTask(task, "Remote callback timeout - no requests received");
|
|
}
|
|
|
|
async #failTask(task: NonNullable<FoundTask>, error: string) {
|
|
await $transaction(this.#prismaClient, async (tx) => {
|
|
await tx.taskAttempt.updateMany({
|
|
where: {
|
|
taskId: task.id,
|
|
status: "PENDING",
|
|
},
|
|
data: {
|
|
status: "ERRORED",
|
|
error,
|
|
},
|
|
});
|
|
|
|
await tx.task.update({
|
|
where: { id: task.id },
|
|
data: {
|
|
status: "ERRORED",
|
|
completedAt: new Date(),
|
|
output: error,
|
|
},
|
|
});
|
|
|
|
await this.#resumeRunExecution(task, tx);
|
|
});
|
|
}
|
|
|
|
async #resumeRunExecution(task: NonNullable<FoundTask>, prisma: PrismaClientOrTransaction) {
|
|
await ResumeTaskService.enqueue(task.id, undefined, prisma);
|
|
}
|
|
}
|
|
|
|
async function findTask(prisma: PrismaClient, id: string) {
|
|
return prisma.task.findUnique({
|
|
where: { id },
|
|
include: {
|
|
run: {
|
|
include: {
|
|
environment: true,
|
|
queue: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|