/
worker.go
61 lines (53 loc) · 1.9 KB
/
worker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cadence
import (
"log"
uclient "github.com/indeedeng/iwf/service/client"
"github.com/indeedeng/iwf/service/common/config"
"github.com/indeedeng/iwf/service/interpreter"
"github.com/indeedeng/iwf/service/interpreter/env"
"go.uber.org/cadence/.gen/go/cadence/workflowserviceclient"
"go.uber.org/cadence/worker"
)
type InterpreterWorker struct {
service workflowserviceclient.Interface
closeFunc func()
domain string
worker worker.Worker
tasklist string
}
func NewInterpreterWorker(config config.Config, service workflowserviceclient.Interface, domain, tasklist string, closeFunc func(), unifiedClient uclient.UnifiedClient) *InterpreterWorker {
env.SetSharedEnv(config, false, nil, unifiedClient, tasklist)
return &InterpreterWorker{
service: service,
domain: domain,
tasklist: tasklist,
closeFunc: closeFunc,
}
}
func (iw *InterpreterWorker) Close() {
iw.closeFunc()
iw.worker.Stop()
}
func (iw *InterpreterWorker) Start() {
config := env.GetSharedConfig()
options := worker.Options{
MaxConcurrentActivityTaskPollers: 10,
MaxConcurrentDecisionTaskPollers: 10,
}
if config.Interpreter.Cadence != nil && config.Interpreter.Cadence.WorkerOptions != nil {
options = *config.Interpreter.Cadence.WorkerOptions
}
iw.worker = worker.New(iw.service, iw.domain, iw.tasklist, options)
worker.EnableVerboseLogging(config.Interpreter.VerboseDebug)
iw.worker.RegisterWorkflow(Interpreter)
iw.worker.RegisterWorkflow(WaitforStateCompletionWorkflow)
iw.worker.RegisterActivity(interpreter.StateStart) // TODO: remove in next release
iw.worker.RegisterActivity(interpreter.StateDecide) // TODO: remove in next release
iw.worker.RegisterActivity(interpreter.StateApiWaitUntil)
iw.worker.RegisterActivity(interpreter.StateApiExecute)
iw.worker.RegisterActivity(interpreter.DumpWorkflowInternal)
err := iw.worker.Start()
if err != nil {
log.Fatalln("Unable to start worker", err)
}
}