Features

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.

This job will be inserted into the queue with a scheduled state and the specified scheduled_at time. Once that time has elapsed, the next loop of the Scheduler will move it to available so it can be picked up by an available Client. This means there will always be some delay after the scheduled time (generally less than 5 seconds), so this option is not suitable for running jobs only a few seconds in the future unless the added delay is acceptable.

Previous
Periodic and cron jobs