SERVER / BACKGROUND JOBS

Run scheduled server work

A background job is an imported server function registered with cron. Dowe runs each scheduled execution in an isolated worker without blocking the server.

1 / DEFINE THE WORK

Use an ordinary server function

Jobs do not need a special declaration. Put the reusable work in a server fn, declare its input with params, and keep provider access inside that function.

dowe
import appDb from "@/server/config/database"

fn compactAudit params:{ retentionDays:number }
  query removed conn:appDb.delete table:"audit_events" where:{ olderThanDays:args.retentionDays }
  return value:{ removed:removed }
Concern
Rule

No data

There are no records to display

2 / REGISTER THE SCHEDULE

Attach cron directly to server.init

Import the function in main.dowe and register it under server.init with the explicit fn prop. Cron creates no result binding, the schedule uses five UTC fields, and args must be static JSON because init has no request-local scope.

dowe
import compactAudit from "@/server/tasks/compact-audit"

main
  server port:8080
    init
      cron fn:compactAudit schedule:"0 3 * * *" args:{ retentionDays:30 }
Field
Accepted values

No data

There are no records to display

Cron fields accept *, numeric values, lists, ranges, and steps such as */15. Each server replica owns its own scheduler.

3 / RUNTIME BEHAVIOR

Know what happens when a job runs

Behavior
Result

No data

There are no records to display

Current support does not include source-level cancellation, result inspection, durable delivery, or distributed singleton scheduling.