This commit is contained in:
@@ -255,11 +255,12 @@ router.post("/jobs", jobsLimiter, async (req: Request, res: Response) => {
|
||||
const evalFee = pricingService.calculateEvalFeeSats();
|
||||
const jobId = randomUUID();
|
||||
const invoiceId = randomUUID();
|
||||
const createdAt = new Date();
|
||||
|
||||
const lnbitsInvoice = await lnbitsService.createInvoice(evalFee, `Eval fee for job ${jobId}`);
|
||||
|
||||
await db.transaction(async (tx) => {
|
||||
await tx.insert(jobs).values({ id: jobId, request, state: "awaiting_eval_payment", evalAmountSats: evalFee });
|
||||
await tx.insert(jobs).values({ id: jobId, request, state: "awaiting_eval_payment", evalAmountSats: evalFee, createdAt });
|
||||
await tx.insert(invoices).values({
|
||||
id: invoiceId,
|
||||
jobId,
|
||||
@@ -276,6 +277,7 @@ router.post("/jobs", jobsLimiter, async (req: Request, res: Response) => {
|
||||
|
||||
res.status(201).json({
|
||||
jobId,
|
||||
createdAt: createdAt.toISOString(),
|
||||
evalInvoice: {
|
||||
paymentRequest: lnbitsInvoice.paymentRequest,
|
||||
amountSats: evalFee,
|
||||
@@ -303,7 +305,11 @@ router.get("/jobs/:id", async (req: Request, res: Response) => {
|
||||
const advanced = await advanceJob(job);
|
||||
if (advanced) job = advanced;
|
||||
|
||||
const base = { jobId: job.id, state: job.state };
|
||||
const base = {
|
||||
jobId: job.id,
|
||||
state: job.state,
|
||||
createdAt: job.createdAt.toISOString(),
|
||||
};
|
||||
|
||||
switch (job.state) {
|
||||
case "awaiting_eval_payment": {
|
||||
@@ -350,6 +356,7 @@ router.get("/jobs/:id", async (req: Request, res: Response) => {
|
||||
case "complete":
|
||||
res.json({
|
||||
...base,
|
||||
completedAt: job.updatedAt.toISOString(),
|
||||
result: job.result ?? undefined,
|
||||
...(job.actualCostUsd != null ? {
|
||||
costLedger: {
|
||||
|
||||
Reference in New Issue
Block a user