Skip to content

Commit d154ab0

Browse files
Relocate workflow and activity registration functions to separate interfaces (#1034)
1 parent 29adafd commit d154ab0

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

worker/worker.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ type (
3737
// Worker hosts workflow and activity implementations.
3838
// Use worker.New(...) to create an instance.
3939
Worker interface {
40+
Registry
41+
42+
// Start starts the worker in a non-blocking fashion
43+
Start() error
44+
// Run is a blocking start and cleans up resources when killed
45+
// returns error only if it fails to start the worker
46+
Run() error
47+
// Stop cleans up any resources opened by worker
48+
Stop()
49+
}
50+
51+
52+
// Registry exposes registration functions to consumers.
53+
Registry interface {
54+
WorkflowRegistry
55+
ActivityRegistry
56+
}
57+
58+
// WorkflowRegistry exposes workflow registration functions to consumers.
59+
WorkflowRegistry interface {
4060
// RegisterWorkflow - registers a workflow function with the worker.
4161
// A workflow takes a workflow.Context and input and returns a (result, error) or just error.
4262
// Examples:
@@ -57,7 +77,10 @@ type (
5777
// This method panics if workflowFunc doesn't comply with the expected format or tries to register the same workflow
5878
// type name twice. Use workflow.RegisterOptions.DisableAlreadyRegisteredCheck to allow multiple registrations.
5979
RegisterWorkflowWithOptions(w interface{}, options workflow.RegisterOptions)
80+
}
6081

82+
// ActivityRegistry exposes activity registration functions to consumers.
83+
ActivityRegistry interface {
6184
// RegisterActivity - register an activity function or a pointer to a structure with the worker.
6285
// An activity function takes a context and input and returns a (result, error) or just error.
6386
//
@@ -106,14 +129,6 @@ type (
106129
// which might be useful for integration tests.
107130
// worker.RegisterActivityWithOptions(barActivity, RegisterActivityOptions{DisableAlreadyRegisteredCheck: true})
108131
RegisterActivityWithOptions(a interface{}, options activity.RegisterOptions)
109-
110-
// Start starts the worker in a non-blocking fashion
111-
Start() error
112-
// Run is a blocking start and cleans up resources when killed
113-
// returns error only if it fails to start the worker
114-
Run() error
115-
// Stop cleans up any resources opened by worker
116-
Stop()
117132
}
118133

119134
// WorkflowReplayer supports replaying a workflow from its event history.

0 commit comments

Comments
 (0)