Durations and sleep
Bound task duration and use provider-backed durable sleep.
Pause task execution through the provider’s durable sleep capability when the selected provider supports it.
Set maxDuration or maxElapsed on the task. Duration values are enforced by the runtime and should be
shorter than the provider’s own request timeout.
/** 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;
Durable sleep records a continuation with the provider. A durable task calls
context.sleep("1 hour", { key: "wait-before-notifying" }); it must not use setTimeout in a worker
process because a restart would lose the continuation.
Providers differ. Inngest currently supports durable sleep for its supported path. Effect MQ does not advertise durable sleep. Trigger Docker does not claim checkpointed sleep. Check capabilities before relying on a long pause.
Use UTC for provider-native schedules. A task that needs a local business timezone should calculate the next instant explicitly and persist the business timezone in its input.