Skip to content

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

tscolari
Copy link

@tscolari tscolari commented Jul 17, 2025

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 the 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).
I can't explain why the goplayground returns a different value here. But according to the codebase tests, the code is correct as it was.

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:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

@tscolari tscolari requested review from a team as code owners July 17, 2025 09:20
tscolari added 2 commits July 17, 2025 10:20
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
@tscolari tscolari force-pushed the support-named-workflows-and-activities branch from 126dd36 to 40fed9b Compare July 17, 2025 09:21
tscolari and others added 2 commits July 17, 2025 11:07
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>
@tscolari tscolari force-pushed the support-named-workflows-and-activities branch from 05e9a82 to 3bc00c8 Compare July 17, 2025 10:11
Signed-off-by: Tiago Scolari <tiago@diagrid.io>
@tscolari tscolari force-pushed the support-named-workflows-and-activities branch from 553a2a8 to 5fb3c61 Compare July 17, 2025 12:56
Copy link
Member

@mikeee mikeee left a 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

Comment on lines 135 to 140
options := registerOptions{}
for _, opt := range opts {
if err := opt(&options); err != nil {
return fmt.Errorf("failed processing options: %w", err)
}
}
Copy link
Member

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?


// 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 {
Copy link
Member

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?

Copy link
Author

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

Copy link
Member

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

tscolari added 3 commits July 17, 2025 16:23
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>
@tscolari tscolari force-pushed the support-named-workflows-and-activities branch from 1501ada to b82732f Compare July 17, 2025 15:24
Copy link

codecov bot commented Jul 17, 2025

Codecov Report

Attention: Patch coverage is 81.08108% with 7 lines in your changes missing coverage. Please review.

Project coverage is 57.19%. Comparing base (6c59092) to head (e07bd78).
Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
workflow/worker.go 81.08% 6 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (6c59092) and HEAD (e07bd78). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (6c59092) HEAD (e07bd78)
4 1
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Custom Names for Workflows and Activities (and support to anonymous functions)
3 participants