-
Notifications
You must be signed in to change notification settings - Fork 181
Support named workflows and activities #744
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
base: main
Are you sure you want to change the base?
Support named workflows and activities #744
Conversation
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
126dd36
to
40fed9b
Compare
Co-authored-by: Joni Collinge <jonathancollinge@live.com> Signed-off-by: Tiago Scolari <38940+tscolari@users.noreply.github.com>
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
05e9a82
to
3bc00c8
Compare
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
553a2a8
to
5fb3c61
Compare
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.
Could you please update the unit tests also
workflow/worker.go
Outdated
options := registerOptions{} | ||
for _, opt := range opts { | ||
if err := opt(&options); err != nil { | ||
return fmt.Errorf("failed processing options: %w", err) | ||
} | ||
} |
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.
Could this be extracted into a separate function since it's reused?
workflow/worker.go
Outdated
|
||
// RegisterWithName allows you to specify a custom name for the workflow or activity being registered. | ||
// Activities and Workflows registered without an explicit name will use the function name as the name. | ||
func RegisterWithName(name string) registerOption { |
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.
Since it's wholly within the workflow package I think WithName
makes sense, wdyt?
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 do!
The main reason was that this same file has some worker options too, that were prefixed with Worker
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.
Fair point, I definitely think I should have added it as a wrapped function as it's probably never used other than in testing
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
Revert changes on the anonymous function detection. Signed-off-by: Tiago Scolari <tiago@diagrid.io>
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
1501ada
to
b82732f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #744 +/- ##
==========================================
- Coverage 62.52% 57.19% -5.34%
==========================================
Files 56 58 +2
Lines 4139 4450 +311
==========================================
- Hits 2588 2545 -43
- Misses 1425 1767 +342
- Partials 126 138 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
This is a small change to allow Workflows and Activities to have custom names - and not only to have them assumed from function names.
The main goal of this is to allow patterns like Workflow/Activity factories, that could return functions to be registered as such.
This tries to not add a breaking change to the methods signatures by allowing it to be set as an "optional" options.
This also fixes theI can't explain why the goplayground returns a different value here. But according to the codebase tests, the code is correct as it was.getFunctionName
function that is currently used to infer the workflow/activity name.It seems to be supposed to avoid anonymous functions, but the verification is wrong, which means it's actually allowing them to be registered (although because the randomness of the name, they would never be able to be called).
Issue reference
#743
Please reference the issue this PR will close: #743
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: