20CAKE20.JS
11-server

Server

11

server/tasks/report.job.ts

Background Job

Example

Process retryable work with typed sample input.

export const config = {
  filter: {
    name: z.string().min(1).max(80),
  },
  sample: {
    name: "Weekly sales",
  },
  attempts: 3,
  backoff: 1000,
};

export default async (data: Input<typeof config.filter>) => {
  const rows = await db.order.findMany({
    select: { item: true, amount: true },
  });
  const file = await excel.save("reports/weekly.xlsx", [
    ["Item", "Amount"],
    ...rows.map((row) => [row.item, row.amount]),
  ]);
  return { name: data.name, path: file.path, rows: rows.length };
};