-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add capability to schedule periodic jobs dynamically (#288)
Here, attempt to resolve #242 by providing a way for new periodic jobs to be added dynamically after a client's already started (i.e. not only by passing them to the client's initial constructor). The new API puts all functions on a separate `PeriodicJobs` bundle to avoid further polluting `Client`'s namespace, and to make all related functions easy to find. riverClient.PeriodicJobs().Add( river.NewPeriodicJob( river.PeriodicInterval(15*time.Minute), func() (river.JobArgs, *river.InsertOpts) { return PeriodicJobArgs{}, nil }, nil, ), ) Additions return a periodic job "handle" which can be used to remove an added job: periodicJobHandle := riverClient.PeriodicJobs().Add(...) riverClient.PeriodicJobs().Remove(periodicJobHandle) I used a handle because the `river.PeriodicJob` construct isn't particularly pretty to keep around, and contains a number of fields that are aren't comparable so its unsuitable for use in equality checks or as a map key. Adding a new periodic job bumps the enqueuer's run loop so that it enqueues the job immediately if it's configured with `RunOnStart`, and schedules its initial target run time. In other words, adding or removing periodic jobs should take effect ~instantly. Fixes #242.
- Loading branch information
Showing
10 changed files
with
737 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.