Execution policy
Control concurrency, duration, admission, and cancellation.
Set retry, timeout, concurrency, and cancellation policy on the task that owns the work.
Execution policy belongs to the task because it describes how the durable operation runs.
/** Produces demonstration CSV through the ordinary order helper and emits validated progress around the durable export. */
import { defineTask } from "@relkit/app/tasks";
import { z } from "@relkit/app/schema";
import { exportOrderCsv } from "../helpers/fake-business.js";
const exportOrders = defineTask({
id: "orders.export-orders",
version: "1",
execution: "durable",
input: z.object({ orderIds: z.array(z.string()) }),
output: z.object({ csv: z.string(), exported: z.number().int().nonnegative() }),
progress: z.object({
completed: z.number().int().nonnegative(),
total: z.number().int().positive(),
}),
handler: async ({ orderIds }, context) => {
await context.progress.emit({ completed: 0, total: orderIds.length });
const csv = exportOrderCsv(orderIds);
await context.progress.emit({ completed: orderIds.length, total: orderIds.length });
return { csv, exported: orderIds.length };
},
});
export default exportOrders;
Use task fields such as maxDuration, maxElapsed, resources, concurrency, logging, and retry.
Jobs keep admission and client exposure together; they do not override task execution policy.
Admission runs before a durable run is accepted. Keep admission checks fast and deterministic. Authorization belongs at the public boundary; the task must still validate every value it trusts from persisted input.
Cancellation is cooperative: the runtime records the requested state and the task should stop between side effects or checkpointable work. Do not delete a run to cancel it. Use the run control API so the provider can retain history and the operation ID can be audited.
The default run-list limit is 25 and the maximum is 100. Provider-specific ceilings are reported by relkit jobs capabilities.