@@ -113,18 +113,41 @@ func wrapWorkflow(w Workflow) task.Orchestrator {
113113 }
114114}
115115
116+ type registerOptions struct {
117+ Name string
118+ }
119+
120+ type registerOption func (* registerOptions ) error
121+
122+ func RegisterWithName (name string ) registerOption {
123+ return func (opts * registerOptions ) error {
124+ opts .Name = name
125+ return nil
126+ }
127+ }
128+
116129// RegisterWorkflow adds a workflow function to the registry
117- func (ww * WorkflowWorker ) RegisterWorkflow (w Workflow ) error {
130+ func (ww * WorkflowWorker ) RegisterWorkflow (w Workflow , opts ... registerOption ) error {
118131 wrappedOrchestration := wrapWorkflow (w )
119132
120- // get the function name for the passed workflow
121- name , err := getFunctionName (w )
122- if err != nil {
123- return fmt .Errorf ("failed to get workflow decorator: %v" , err )
133+ options := registerOptions {}
134+ for _ , opt := range opts {
135+ if err := opt (& options ); err != nil {
136+ return fmt .Errorf ("failed processing options: %w" , err )
137+ }
124138 }
125139
126- err = ww .tasks .AddOrchestratorN (name , wrappedOrchestration )
127- return err
140+ if options .Name != "" {
141+ // get the function name for the passed workflow if there's
142+ // no explicit name provided.
143+ name , err := getFunctionName (w )
144+ if err != nil {
145+ return fmt .Errorf ("failed to get workflow decorator: %v" , err )
146+ }
147+ options .Name = name
148+ }
149+
150+ return ww .tasks .AddOrchestratorN (options .Name , wrappedOrchestration )
128151}
129152
130153func wrapActivity (a Activity ) task.Activity {
@@ -142,17 +165,27 @@ func wrapActivity(a Activity) task.Activity {
142165}
143166
144167// RegisterActivity adds an activity function to the registry
145- func (ww * WorkflowWorker ) RegisterActivity (a Activity ) error {
168+ func (ww * WorkflowWorker ) RegisterActivity (a Activity , opts ... registerOption ) error {
146169 wrappedActivity := wrapActivity (a )
147170
148- // get the function name for the passed activity
149- name , err := getFunctionName (a )
150- if err != nil {
151- return fmt .Errorf ("failed to get activity decorator: %v" , err )
171+ options := registerOptions {}
172+ for _ , opt := range opts {
173+ if err := opt (& options ); err != nil {
174+ return fmt .Errorf ("failed processing options: %w" , err )
175+ }
176+ }
177+
178+ if options .Name != "" {
179+ // get the function name for the passed workflow if there's
180+ // no explicit name provided.
181+ name , err := getFunctionName (a )
182+ if err != nil {
183+ return fmt .Errorf ("failed to get activity decorator: %v" , err )
184+ }
185+ options .Name = name
152186 }
153187
154- err = ww .tasks .AddActivityN (name , wrappedActivity )
155- return err
188+ return ww .tasks .AddActivityN (options .Name , wrappedActivity )
156189}
157190
158191// Start initialises a non-blocking worker to handle workflows and activities registered
0 commit comments