@@ -14,6 +14,7 @@ import (
1414 "github.com/riverqueue/river/riverdriver"
1515 "github.com/riverqueue/river/rivershared/baseservice"
1616 "github.com/riverqueue/river/rivershared/circuitbreaker"
17+ "github.com/riverqueue/river/rivershared/riverpilot"
1718 "github.com/riverqueue/river/rivershared/riversharedmaintenance"
1819 "github.com/riverqueue/river/rivershared/startstop"
1920 "github.com/riverqueue/river/rivershared/testsignal"
@@ -50,6 +51,9 @@ type JobRescuerConfig struct {
5051 // Interval is the amount of time to wait between runs of the rescuer.
5152 Interval time.Duration
5253
54+ // Pilot controls driver-level behavior that can be customized by plugins.
55+ Pilot riverpilot.Pilot
56+
5357 // RescueAfter is the amount of time for a job to be active before it is
5458 // considered stuck and should be rescued.
5559 RescueAfter time.Duration
@@ -70,6 +74,9 @@ func (c *JobRescuerConfig) mustValidate() *JobRescuerConfig {
7074 if c .Interval <= 0 {
7175 panic ("RescuerConfig.Interval must be above zero" )
7276 }
77+ if c .Pilot == nil {
78+ panic ("RescuerConfig.Pilot must be set" )
79+ }
7380 if c .RescueAfter <= 0 {
7481 panic ("RescuerConfig.JobDuration must be above zero" )
7582 }
@@ -103,12 +110,17 @@ type JobRescuer struct {
103110
104111func NewRescuer (archetype * baseservice.Archetype , config * JobRescuerConfig , exec riverdriver.Executor ) * JobRescuer {
105112 batchSizes := config .WithDefaults ()
113+ pilot := config .Pilot
114+ if pilot == nil {
115+ pilot = & riverpilot.StandardPilot {}
116+ }
106117
107118 return baseservice .Init (archetype , & JobRescuer {
108119 Config : (& JobRescuerConfig {
109120 BatchSizes : batchSizes ,
110121 ClientRetryPolicy : config .ClientRetryPolicy ,
111122 Interval : cmp .Or (config .Interval , JobRescuerIntervalDefault ),
123+ Pilot : pilot ,
112124 RescueAfter : cmp .Or (config .RescueAfter , JobRescuerRescueAfterDefault ),
113125 Schema : config .Schema ,
114126 WorkUnitFactoryFunc : config .WorkUnitFactoryFunc ,
@@ -253,7 +265,7 @@ func (s *JobRescuer) runOnce(ctx context.Context) (*rescuerRunOnceResult, error)
253265 }
254266
255267 if len (rescueManyParams .ID ) > 0 {
256- _ , err = s .exec . JobRescueMany (ctx , & rescueManyParams )
268+ _ , err = s .Config . Pilot . JobRescueMany (ctx , s . exec , & rescueManyParams )
257269 if err != nil {
258270 return nil , fmt .Errorf ("error rescuing stuck jobs: %w" , err )
259271 }
0 commit comments