Skip to content

Commit

Permalink
Rename Constant FailurePolicy delay to interval
Browse files Browse the repository at this point in the history
Signed-off-by: joshvanl <[email protected]>
  • Loading branch information
JoshVanL committed Oct 14, 2024
1 parent 2f44665 commit 4509ffa
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 79 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ A Job itself is made up of the following fields:
Optional.
- `FailurePolicy` Controls whether the Job should be retired if the trigger
function returns false. `Drop` doesn't retry the job, `Constant `Constant` will
constantly retry the job trigger for a configurable delay, up to a configurable
constantly retry the job trigger for a configurable internal, up to a configurable
maximum number of retries (which could be infinite). By default, Jobs have a
`Constant` policy, with a 1s delay and 3 maximum retries.
`Constant` policy, with a 1s interval and 3 maximum retries.

A job must have *at least* either a `Schedule` or a `DueTime` set.

Expand Down
37 changes: 19 additions & 18 deletions api/failurepolicy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/job.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func Test_jobWithSpace(t *testing.T) {
func Test_FailurePolicy(t *testing.T) {
t.Parallel()

t.Run("default policy should retry 3 times with a 1sec delay", func(t *testing.T) {
t.Run("default policy should retry 3 times with a 1sec interval", func(t *testing.T) {
t.Parallel()

gotCh := make(chan *api.TriggerRequest, 1)
Expand Down Expand Up @@ -641,7 +641,7 @@ func Test_FailurePolicy(t *testing.T) {
FailurePolicy: &api.FailurePolicy{
Policy: &api.FailurePolicy_Constant{
Constant: &api.FailurePolicyConstant{
Delay: durationpb.New(time.Millisecond), MaxRetries: ptr.Of(uint32(1)),
Interval: durationpb.New(time.Millisecond), MaxRetries: ptr.Of(uint32(1)),
},
},
},
Expand Down Expand Up @@ -685,7 +685,7 @@ func Test_FailurePolicy(t *testing.T) {
FailurePolicy: &api.FailurePolicy{
Policy: &api.FailurePolicy_Constant{
Constant: &api.FailurePolicyConstant{
Delay: durationpb.New(time.Millisecond),
Interval: durationpb.New(time.Millisecond),
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions internal/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Test_CRUD(t *testing.T) {
DueTime: ptr.Of(now.Add(time.Hour).Format(time.RFC3339)),
FailurePolicy: &cronapi.FailurePolicy{Policy: &cronapi.FailurePolicy_Constant{
Constant: &cronapi.FailurePolicyConstant{
Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
},
}},
}, resp)
Expand All @@ -58,7 +58,7 @@ func Test_CRUD(t *testing.T) {
DueTime: ptr.Of(newNow.Add(time.Hour).Format(time.RFC3339)),
FailurePolicy: &cronapi.FailurePolicy{Policy: &cronapi.FailurePolicy_Constant{
Constant: &cronapi.FailurePolicyConstant{
Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
},
}},
}))
Expand All @@ -68,7 +68,7 @@ func Test_CRUD(t *testing.T) {
DueTime: ptr.Of(newNow.Add(time.Hour).Format(time.RFC3339)),
FailurePolicy: &cronapi.FailurePolicy{Policy: &cronapi.FailurePolicy_Constant{
Constant: &cronapi.FailurePolicyConstant{
Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
},
}},
}, resp)
Expand All @@ -83,7 +83,7 @@ func Test_CRUD(t *testing.T) {
DueTime: ptr.Of(now.Add(time.Hour).Format(time.RFC3339)),
FailurePolicy: &cronapi.FailurePolicy{Policy: &cronapi.FailurePolicy_Constant{
Constant: &cronapi.FailurePolicyConstant{
Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
},
}},
}))
Expand All @@ -94,7 +94,7 @@ func Test_CRUD(t *testing.T) {
DueTime: ptr.Of(now.Add(time.Hour).Format(time.RFC3339)),
FailurePolicy: &cronapi.FailurePolicy{Policy: &cronapi.FailurePolicy_Constant{
Constant: &cronapi.FailurePolicyConstant{
Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)),
},
}},
}, resp)
Expand Down
2 changes: 1 addition & 1 deletion internal/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (c *Counter) policyTryAgain() bool {
//nolint:protogetter
tryAgain := p.Constant.MaxRetries == nil || *p.Constant.MaxRetries >= c.count.Attempts
if tryAgain {
c.next = c.next.Add(p.Constant.GetDelay().AsDuration())
c.next = c.next.Add(p.Constant.GetInterval().AsDuration())
} else {
// We set the LastTrigger to the first attempt to ensure consistency of
// the Job schedule, regardless of the failure policy cadence and
Expand Down
Loading

0 comments on commit 4509ffa

Please sign in to comment.