-
Notifications
You must be signed in to change notification settings - Fork 183
Exposes FailurePolicy to the Jobs api #737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the name change to jobs
for consistency across dapr repos - I've been wanting to update that for a while now 🙌🏻
client/jobs.go
Outdated
Name string | ||
Schedule string // Optional | ||
Repeats uint32 // Optional | ||
DueTime string // Optional | ||
TTL string // Optional | ||
Data *anypb.Any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional fields should be pointers.
client/jobs.go
Outdated
if job.Schedule != "" { | ||
jobRequest.Schedule = &job.Schedule | ||
} | ||
|
||
if job.Repeats != 0 { | ||
jobRequest.Repeats = &job.Repeats | ||
} | ||
|
||
if job.DueTime != "" { | ||
jobRequest.DueTime = &job.DueTime | ||
} | ||
|
||
if job.TTL != "" { | ||
jobRequest.Ttl = &job.TTL | ||
} | ||
|
||
if job.FailurePolicy != nil { | ||
jobRequest.FailurePolicy = job.FailurePolicy.GetPBFailurePolicy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigned pointers to pointers. We shouldn't empty string match.
client/jobs.go
Outdated
resp, err := c.protoClient.GetJobAlpha1(ctx, &runtimepb.GetJobRequest{ | ||
Name: name, | ||
}) | ||
log.Println(resp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove.
client/jobs.go
Outdated
func (f *JobFailurePolicyConstant) GetPBFailurePolicy() *commonpb.JobFailurePolicy { | ||
policy := &commonpb.JobFailurePolicy{ | ||
Policy: &commonpb.JobFailurePolicy_Constant{ | ||
Constant: &commonpb.JobFailurePolicyConstant{}, | ||
}, | ||
} | ||
if f.maxRetries != nil { | ||
policy.Policy.(*commonpb.JobFailurePolicy_Constant).Constant.MaxRetries = f.maxRetries | ||
} | ||
if f.interval != nil { | ||
policy.Policy.(*commonpb.JobFailurePolicy_Constant).Constant.Interval = &durationpb.Duration{Seconds: int64(f.interval.Seconds())} | ||
} | ||
return policy | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why and what is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JobFailurePolicyConstant
is the exposed type the SDK users can use to assign FailurePolicies. This function then converts this exposed type into the corresponding policy from the commonpb
package.
client/jobs.go
Outdated
func (f *JobFailurePolicyConstant) GetPBFailurePolicy() *commonpb.JobFailurePolicy { | ||
policy := &commonpb.JobFailurePolicy{ | ||
Policy: &commonpb.JobFailurePolicy_Constant{ | ||
Constant: &commonpb.JobFailurePolicyConstant{}, | ||
}, | ||
} | ||
if f.maxRetries != nil { | ||
policy.Policy.(*commonpb.JobFailurePolicy_Constant).Constant.MaxRetries = f.maxRetries | ||
} | ||
if f.interval != nil { | ||
policy.Policy.(*commonpb.JobFailurePolicy_Constant).Constant.Interval = &durationpb.Duration{Seconds: int64(f.interval.Seconds())} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this not be built in a better way to avoid type casting the proto pointer?
c33b552
to
ae9a14e
Compare
Also: - Refactor how exposed type is converted to proto type - Remove unnecesary log - Input validation for job api calls Signed-off-by: Albert Callarisa <[email protected]>
ae9a14e
to
88a5872
Compare
examples/go.sum
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Examples folder needs a go mod tidy
as v1.15.5 is still vendored it seems
client/client_test.go
Outdated
dueTime = "10s" | ||
repeats uint32 = 4 | ||
ttl = "10s" | ||
maxRetries = uint32(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxRetries = uint32(4) | |
maxRetries uint32 = 4 |
client/jobs.go
Outdated
} | ||
} | ||
|
||
func NewFailurePolicyConstant(maxRetries *uint32, interval *time.Duration) FailurePolicy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function signature doesn't appear idiomatic to me... having to pass an address of an unsigned in and again the address of a duration
I would have liked to see the values passed directly e.g. NewFailurePolicyConstant(4, time.Second * 5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll actually remove those 'constructor' functions, as they are now unnecessary (those types were not exposed previously). I think it'll cleaner just to provide the appropriate struct directly, like the following:
&Job{
Name: "name",
Schedule: &schedule,
Repeats: &repeats,
DueTime: &dueTime,
TTL: &ttl,
Data: nil,
FailurePolicy: &JobFailurePolicyConstant{
maxRetries: &maxRetries,
interval: &interval,
},
}
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this! I posted #737 (comment)
I think the functional options pattern is more idiomatic whether applied directly on the Job
or as an optional overload to the ScheduleJobAlpha1
method
examples/jobs/main.go
Outdated
maxRetries := uint32(4) | ||
interval := time.Second * 3 | ||
job := daprc.Job{ | ||
Name: "prod-db-backup", | ||
Schedule: "@every 1s", | ||
Repeats: 10, | ||
Data: &anypb.Any{ | ||
Value: jobData, | ||
}, | ||
FailurePolicy: daprc.NewFailurePolicyConstant(&maxRetries, &interval), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think from this example it's clear that using the addresses of an int or duration adds unnecessary faff in my opinion
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
We can pass the right types directly when building jobs, there's no need for a constructor. The constructor was used previously when the types were private, but now they are exposed so the constructor is unnecessary. Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, would be good to see some test assertions for those functional options just to cover any future upstream changes for this Alpha api
Signed-off-by: Albert Callarisa <[email protected]>
@mikeee What do you think now? |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #737 +/- ##
==========================================
- Coverage 62.52% 57.18% -5.35%
==========================================
Files 56 58 +2
Lines 4139 4428 +289
==========================================
- Hits 2588 2532 -56
- Misses 1425 1761 +336
- Partials 126 135 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acroca Looking good, I think the linter isn't happy with the way you're accessing the proto fields but aside from that it looks fine to me.
Could you please address two things also:
- Deps issue whereby the JobFailurePolicy is not found, assumign this is a result of whichever commit hash you've used
- Update the workflow (https://github.com/dapr/go-sdk/blob/main/.github/workflows/validate_examples.yaml) rename the 'dist-scheduler' item to 'jobs'
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
Signed-off-by: Albert Callarisa <[email protected]>
@mikeee better now? The failing test seems to be github related, re-running it should work (works on my machine ™) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm- the tests are flaky when initialising dapr.
Cool, what's left to merge this PR? |
Description
dapr/dapr#8785 has been merged into master. That PR exposes
FailurePolicy
field in the Jobs APIChecklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: