diff --git a/README.md b/README.md index a2478dc..0059fd9 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/api/failurepolicy.pb.go b/api/failurepolicy.pb.go index f663e42..b5d6139 100644 --- a/api/failurepolicy.pb.go +++ b/api/failurepolicy.pb.go @@ -150,14 +150,14 @@ func (*FailurePolicyDrop) Descriptor() ([]byte, []int) { } // FailurePolicyRetry is a policy which retries the job at a consistent -// delay when the job fails to trigger. +// interval when the job fails to trigger. type FailurePolicyConstant struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // delay is the constant delay to wait before retrying the job. - Delay *durationpb.Duration `protobuf:"bytes,1,opt,name=delay,proto3" json:"delay,omitempty"` + // interval is the constant delay to wait before retrying the job. + Interval *durationpb.Duration `protobuf:"bytes,1,opt,name=interval,proto3" json:"interval,omitempty"` // max_retries is the optional maximum number of retries to attempt before // giving up. // If unset, the Job will be retried indefinitely. @@ -196,9 +196,9 @@ func (*FailurePolicyConstant) Descriptor() ([]byte, []int) { return file_proto_api_failurepolicy_proto_rawDescGZIP(), []int{2} } -func (x *FailurePolicyConstant) GetDelay() *durationpb.Duration { +func (x *FailurePolicyConstant) GetInterval() *durationpb.Duration { if x != nil { - return x.Delay + return x.Interval } return nil } @@ -226,18 +226,19 @@ var file_proto_api_failurepolicy_proto_rawDesc = []byte{ 0x6c, 0x75, 0x72, 0x65, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x43, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x42, 0x08, 0x0a, 0x06, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x22, 0x13, 0x0a, 0x11, 0x46, 0x61, 0x69, 0x6c, - 0x75, 0x72, 0x65, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x44, 0x72, 0x6f, 0x70, 0x22, 0x7e, 0x0a, - 0x15, 0x46, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x43, 0x6f, - 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x52, 0x05, 0x64, 0x65, 0x6c, 0x61, 0x79, 0x12, 0x24, 0x0a, 0x0b, 0x6d, 0x61, 0x78, 0x5f, 0x72, - 0x65, 0x74, 0x72, 0x69, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x0a, - 0x6d, 0x61, 0x78, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65, 0x73, 0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, - 0x0c, 0x5f, 0x6d, 0x61, 0x78, 0x5f, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x73, 0x42, 0x27, 0x5a, - 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x69, 0x61, 0x67, - 0x72, 0x69, 0x64, 0x69, 0x6f, 0x2f, 0x67, 0x6f, 0x2d, 0x65, 0x74, 0x63, 0x64, 0x2d, 0x63, 0x72, - 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x75, 0x72, 0x65, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x44, 0x72, 0x6f, 0x70, 0x22, 0x84, 0x01, + 0x0a, 0x15, 0x46, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x43, + 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x12, 0x35, 0x0a, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x76, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x12, 0x24, + 0x0a, 0x0b, 0x6d, 0x61, 0x78, 0x5f, 0x72, 0x65, 0x74, 0x72, 0x69, 0x65, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x0a, 0x6d, 0x61, 0x78, 0x52, 0x65, 0x74, 0x72, 0x69, 0x65, + 0x73, 0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x6d, 0x61, 0x78, 0x5f, 0x72, 0x65, 0x74, + 0x72, 0x69, 0x65, 0x73, 0x42, 0x27, 0x5a, 0x25, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x64, 0x69, 0x61, 0x67, 0x72, 0x69, 0x64, 0x69, 0x6f, 0x2f, 0x67, 0x6f, 0x2d, + 0x65, 0x74, 0x63, 0x64, 0x2d, 0x63, 0x72, 0x6f, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -262,7 +263,7 @@ var file_proto_api_failurepolicy_proto_goTypes = []interface{}{ var file_proto_api_failurepolicy_proto_depIdxs = []int32{ 1, // 0: api.FailurePolicy.drop:type_name -> api.FailurePolicyDrop 2, // 1: api.FailurePolicy.constant:type_name -> api.FailurePolicyConstant - 3, // 2: api.FailurePolicyConstant.delay:type_name -> google.protobuf.Duration + 3, // 2: api.FailurePolicyConstant.interval:type_name -> google.protobuf.Duration 3, // [3:3] is the sub-list for method output_type 3, // [3:3] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name diff --git a/api/job.pb.go b/api/job.pb.go index 8fcdfb2..15dd2ca 100644 --- a/api/job.pb.go +++ b/api/job.pb.go @@ -73,7 +73,7 @@ type Job struct { Payload *anypb.Any `protobuf:"bytes,6,opt,name=payload,proto3" json:"payload,omitempty"` // failure_policy is the optional policy to apply when a job fails to // trigger. - // By default, the failure policy is FailurePolicyConstant with a 1s delay + // By default, the failure policy is FailurePolicyConstant with a 1s interval // and 3 maximum retries. // See `failurepolicy.proto` for more information. FailurePolicy *FailurePolicy `protobuf:"bytes,7,opt,name=failure_policy,json=failurePolicy,proto3,oneof" json:"failure_policy,omitempty"` diff --git a/cron/cron_test.go b/cron/cron_test.go index 4577d8b..7841cd7 100644 --- a/cron/cron_test.go +++ b/cron/cron_test.go @@ -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) @@ -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)), }, }, }, @@ -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), }, }, }, diff --git a/internal/api/api_test.go b/internal/api/api_test.go index cce9b3e..94e238d 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -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) @@ -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)), }, }}, })) @@ -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) @@ -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)), }, }}, })) @@ -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) diff --git a/internal/counter/counter.go b/internal/counter/counter.go index 2d520de..93f09a8 100644 --- a/internal/counter/counter.go +++ b/internal/counter/counter.go @@ -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 diff --git a/internal/counter/counter_test.go b/internal/counter/counter_test.go index 124b978..018a99d 100644 --- a/internal/counter/counter_test.go +++ b/internal/counter/counter_test.go @@ -1150,13 +1150,13 @@ func Test_TriggerFailed(t *testing.T) { expPut: nil, expDel: ptr.Of("abc/jobs/1"), }, - "failure policy Constant default, nil delay and nil max retries, one shot, expect true with Put and next now": { + "failure policy Constant default, nil interval and nil max retries, one shot, expect true with Put and next now": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: nil, MaxRetries: nil, + Interval: nil, MaxRetries: nil, }, }, }, @@ -1175,13 +1175,13 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "failure policy Constant default, nil delay and 0 max retries, one shot, expect false with del": { + "failure policy Constant default, nil interval and 0 max retries, one shot, expect false with del": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: nil, MaxRetries: ptr.Of(uint32(0)), + Interval: nil, MaxRetries: ptr.Of(uint32(0)), }, }, }, @@ -1194,14 +1194,14 @@ func Test_TriggerFailed(t *testing.T) { expPut: nil, expDel: ptr.Of("abc/jobs/1"), }, - "failure policy Constant default, nil delay and 0 max retries, schedule, expect true with count forward": { + "failure policy Constant default, nil interval and 0 max retries, schedule, expect true with count forward": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: nil, MaxRetries: ptr.Of(uint32(0)), + Interval: nil, MaxRetries: ptr.Of(uint32(0)), }, }, }, @@ -1221,7 +1221,7 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "failure policy Constant default, nil delay and 0 max retries, schedule but at expiration, expect false with job delete": { + "failure policy Constant default, nil interval and 0 max retries, schedule but at expiration, expect false with job delete": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), @@ -1229,7 +1229,7 @@ func Test_TriggerFailed(t *testing.T) { FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: nil, MaxRetries: ptr.Of(uint32(0)), + Interval: nil, MaxRetries: ptr.Of(uint32(0)), }, }, }, @@ -1242,13 +1242,13 @@ func Test_TriggerFailed(t *testing.T) { expPut: nil, expDel: ptr.Of("abc/jobs/1"), }, - "failure policy Constant default, 3s delay and nil max retries, one shot, expect true with Put and next now+3s": { + "failure policy Constant default, 3s interval and nil max retries, one shot, expect true with Put and next now+3s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 3), MaxRetries: nil, + Interval: durationpb.New(time.Second * 3), MaxRetries: nil, }, }, }, @@ -1267,14 +1267,14 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "failure policy Constant default, 3s delay and nil max retries, schedule, expect true with Put and next now+3s": { + "failure policy Constant default, 3s interval and nil max retries, schedule, expect true with Put and next now+3s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 3), MaxRetries: nil, + Interval: durationpb.New(time.Second * 3), MaxRetries: nil, }, }, }, @@ -1293,7 +1293,7 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "failure policy Constant default, 3s delay and nil max retries, schedule but at expiration, expect true with Put and next now+9": { + "failure policy Constant default, 3s interval and nil max retries, schedule but at expiration, expect true with Put and next now+9": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), @@ -1301,7 +1301,7 @@ func Test_TriggerFailed(t *testing.T) { FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 3), MaxRetries: nil, + Interval: durationpb.New(time.Second * 3), MaxRetries: nil, }, }, }, @@ -1320,14 +1320,14 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "failure policy Constant default, 3s delay and nil max retries, schedule attempt 5, expect true with Put and next now+3*5": { + "failure policy Constant default, 3s interval and nil max retries, schedule attempt 5, expect true with Put and next now+3*5": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 3), MaxRetries: nil, + Interval: durationpb.New(time.Second * 3), MaxRetries: nil, }, }, }, @@ -1346,14 +1346,14 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "failure policy Constant default, 0s delay and nil max retries, schedule attempt 5, expect true with Put and next now": { + "failure policy Constant default, 0s interval and nil max retries, schedule attempt 5, expect true with Put and next now": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(0), MaxRetries: nil, + Interval: durationpb.New(0), MaxRetries: nil, }, }, }, @@ -1372,14 +1372,14 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "if failure policy is constant with 5s delay and 0 max retries with 0 attempts, schedule, expect true with Put and next now+5s": { + "if failure policy is constant with 5s interval and 0 max retries with 0 attempts, schedule, expect true with Put and next now+5s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(0)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(0)), }, }, }, @@ -1399,13 +1399,13 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "if failure policy is constant with 5s delay and 0 max retries with 0 attempts, one shot, expect false with del job:": { + "if failure policy is constant with 5s interval and 0 max retries with 0 attempts, one shot, expect false with del job:": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(0)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(0)), }, }, }, @@ -1418,14 +1418,14 @@ func Test_TriggerFailed(t *testing.T) { expPut: nil, expDel: ptr.Of("abc/jobs/1"), }, - "if failure policy is constant with 5s delay and 1 max retries with 0 attempts, schedule, expect true with Put and next now+5s": { + "if failure policy is constant with 5s interval and 1 max retries with 0 attempts, schedule, expect true with Put and next now+5s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), }, }, }, @@ -1444,13 +1444,13 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "if failure policy is constant with 5s delay and 1 max retries with 0 attempts, oneshot, expect true with Put and next now+5s": { + "if failure policy is constant with 5s interval and 1 max retries with 0 attempts, oneshot, expect true with Put and next now+5s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), }, }, }, @@ -1470,14 +1470,14 @@ func Test_TriggerFailed(t *testing.T) { expDel: nil, }, - "if failure policy is constant with 5s delay and 1 max retries with 1 attempts, schedule, expect true with count forward and next now+1s": { + "if failure policy is constant with 5s interval and 1 max retries with 1 attempts, schedule, expect true with count forward and next now+1s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), }, }, }, @@ -1497,13 +1497,13 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "if failure policy is constant with 5s delay and 1 max retries with 1 attempts, oneshot, expect false with del job": { + "if failure policy is constant with 5s interval and 1 max retries with 1 attempts, oneshot, expect false with del job": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(1)), }, }, }, @@ -1517,14 +1517,14 @@ func Test_TriggerFailed(t *testing.T) { expDel: ptr.Of("abc/jobs/1"), }, - "if failure policy is constant with 5s delay and 2 max retries with 2 attempts, schedule, expect true with count forward and next now+1s": { + "if failure policy is constant with 5s interval and 2 max retries with 2 attempts, schedule, expect true with count forward and next now+1s": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(2)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(2)), }, }, }, @@ -1544,14 +1544,14 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "if failure policy is constant with 5s delay and 3 max retries with 2 attempts, schedule, expect true with retry": { + "if failure policy is constant with 5s interval and 3 max retries with 2 attempts, schedule, expect true with retry": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(3)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(3)), }, }, }, @@ -1570,14 +1570,14 @@ func Test_TriggerFailed(t *testing.T) { }, expDel: nil, }, - "if failure policy is constant with 5s delay and 2 max retries with 2 attempts, count 3, schedule, expect true with counter forward": { + "if failure policy is constant with 5s interval and 2 max retries with 2 attempts, count 3, schedule, expect true with counter forward": { job: &api.Job{ DueTime: ptr.Of(now.Format(time.RFC3339)), Schedule: ptr.Of("@every 1s"), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(2)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(2)), }, }, }, @@ -1699,7 +1699,7 @@ func Test_TriggerFailureSuccess(t *testing.T) { FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(2)), + Interval: durationpb.New(time.Second * 5), MaxRetries: ptr.Of(uint32(2)), }, }, }, diff --git a/internal/scheduler/builder.go b/internal/scheduler/builder.go index 7e6d517..00b606d 100644 --- a/internal/scheduler/builder.go +++ b/internal/scheduler/builder.go @@ -95,7 +95,7 @@ func (b *Builder) Parse(job *api.Job) (*stored.Job, error) { job.FailurePolicy = &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{ Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second), + Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), }, }, diff --git a/internal/scheduler/builder_test.go b/internal/scheduler/builder_test.go index 50e4f49..f899fa1 100644 --- a/internal/scheduler/builder_test.go +++ b/internal/scheduler/builder_test.go @@ -175,7 +175,7 @@ func Test_Parse(t *testing.T) { Repeats: nil, FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), + Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), }}, }, }, @@ -201,7 +201,7 @@ func Test_Parse(t *testing.T) { Repeats: nil, FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), + Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), }}, }, }, @@ -227,7 +227,7 @@ func Test_Parse(t *testing.T) { Repeats: nil, FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), + Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), }}, }, }, @@ -253,7 +253,7 @@ func Test_Parse(t *testing.T) { Repeats: ptr.Of(uint32(100)), FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), + Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), }}, }, }, @@ -289,7 +289,7 @@ func Test_Parse(t *testing.T) { Repeats: nil, FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), + Interval: durationpb.New(time.Second), MaxRetries: ptr.Of(uint32(3)), }}, }, }, @@ -326,7 +326,7 @@ func Test_Parse(t *testing.T) { Repeats: nil, FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 3), MaxRetries: ptr.Of(uint32(5)), + Interval: durationpb.New(time.Second * 3), MaxRetries: ptr.Of(uint32(5)), }}, }, }, @@ -338,7 +338,7 @@ func Test_Parse(t *testing.T) { Repeats: nil, FailurePolicy: &api.FailurePolicy{ Policy: &api.FailurePolicy_Constant{Constant: &api.FailurePolicyConstant{ - Delay: durationpb.New(time.Second * 3), MaxRetries: ptr.Of(uint32(5)), + Interval: durationpb.New(time.Second * 3), MaxRetries: ptr.Of(uint32(5)), }}, }, }, diff --git a/proto/api/failurepolicy.proto b/proto/api/failurepolicy.proto index 8ce06f3..f2ca4bb 100644 --- a/proto/api/failurepolicy.proto +++ b/proto/api/failurepolicy.proto @@ -25,10 +25,10 @@ message FailurePolicy { message FailurePolicyDrop {} // FailurePolicyRetry is a policy which retries the job at a consistent -// delay when the job fails to trigger. +// interval when the job fails to trigger. message FailurePolicyConstant { - // delay is the constant delay to wait before retrying the job. - google.protobuf.Duration delay = 1; + // interval is the constant delay to wait before retrying the job. + google.protobuf.Duration interval = 1; // max_retries is the optional maximum number of retries to attempt before // giving up. diff --git a/proto/api/job.proto b/proto/api/job.proto index 350d9e4..03865be 100644 --- a/proto/api/job.proto +++ b/proto/api/job.proto @@ -62,7 +62,7 @@ message Job { // failure_policy is the optional policy to apply when a job fails to // trigger. - // By default, the failure policy is FailurePolicyConstant with a 1s delay + // By default, the failure policy is FailurePolicyConstant with a 1s interval // and 3 maximum retries. // See `failurepolicy.proto` for more information. optional FailurePolicy failure_policy = 7;