@@ -113,18 +113,41 @@ func wrapWorkflow(w Workflow) task.Orchestrator {
113
113
}
114
114
}
115
115
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
+
116
129
// 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 {
118
131
wrappedOrchestration := wrapWorkflow (w )
119
132
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
+ }
124
138
}
125
139
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 )
128
151
}
129
152
130
153
func wrapActivity (a Activity ) task.Activity {
@@ -142,17 +165,27 @@ func wrapActivity(a Activity) task.Activity {
142
165
}
143
166
144
167
// 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 {
146
169
wrappedActivity := wrapActivity (a )
147
170
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
152
186
}
153
187
154
- err = ww .tasks .AddActivityN (name , wrappedActivity )
155
- return err
188
+ return ww .tasks .AddActivityN (options .Name , wrappedActivity )
156
189
}
157
190
158
191
// Start initialises a non-blocking worker to handle workflows and activities registered
0 commit comments