Vercel Workflow
Hoikka uses Vercel Workflow for durable, scheduled tasks. Workflows handle retries, scheduling, and observability natively.
Setup
The Workflow plugin is configured in vite.config.ts:
vite.config.ts
import { workflowPlugin } from "workflow/sveltekit";
export default defineConfig({
plugins: [tailwindcss(), sveltekit(), workflowPlugin()]
});Workflow files live in the workflows/ directory.
Writing Workflows
Basic Workflow
workflows/cleanup.ts
import { sleep } from "workflow";
export async function reservationCleanup() {
"use workflow";
while (true) {
await cleanupExpiredReservations();
await sleep("15m");
}
}
async function cleanupExpiredReservations() {
"use step";
const { reservationService } = await import("$lib/server/services/reservations.js");
const count = await reservationService.cleanupExpired();
return { cleaned: count };
}Key Concepts
"use workflow"— marks a function as a durable workflow entry point"use step"— marks a function as an individual step (retried independently)sleep(duration)— durable sleep that survives restarts ("15m","1h","1d")- Steps have full access to Node.js APIs and npm packages
Scheduling Patterns
Recurring
export async function dailySync() {
"use workflow";
while (true) {
await syncProducts();
await sleep("1d");
}
}One-off
import { start } from "workflow";
// Start a workflow programmatically
await start(orderFollowup, [orderId]);Local Development
Run the workflow dashboard locally:
bunx workflow webDeployment
Workflows deploy automatically with your Vercel project. Available on all Vercel plans.
Last updated on