Appearance
Run a report
ts
export async function runReport(reportId: number, from: string, to: string) {
const job = await staff.reports.run(reportId, { from, to, groups: "real\\*" });
// Progress arrives on the socket; poll as a fallback for missed frames.
const socket = staff.socket();
await socket.connect();
try {
await new Promise<void>((resolve) => {
const done = (state?: string) => state === "done" || state === "failed" || state === "cancelled";
socket.on("report_job", (f) => done(f.data.state) && f.data.id === job.id && resolve());
const poll = setInterval(async () => {
const j = await staff.reports.retrieveJobs(job.id);
if (done(j.state)) { clearInterval(poll); resolve(); }
}, 5000);
});
} finally {
socket.close();
}
return staff.reports.retrieveJobs(job.id); // sections: columns, rows, totals
}staff.reports.list() shows the reports you may run and the inputs each module asks for. Export a finished job with staff.reports.jobsExport(id) (the answer is the file as a Response).