Skip to content

Scheduled jobs

Jobs can be scheduled to run at a future time and date instead of running immediately.


Basic usage

At insertion time, any job can specify a ScheduledAt as part of its InsertOpts to run it at a future time. The following code inserts a job that will run three hours from now:

_, err = riverClient.Insert(ctx,
ScheduledArgs{
Message: "hello from the future",
},
&river.InsertOpts{
ScheduledAt: time.Now().Add(3 * time.Hour),
}
)
if err != nil {
// handle error
}

See the ScheduledJob example for complete code.

The job won’t be fetched before its scheduled_at time. The scheduler makes scheduled jobs available when they are due. Scheduling is not an exact timer: maintenance intervals, polling, and worker capacity can all add a delay.