Repository navigation
Expand file tree
/
Copy pathworker.go
More file actions
65 lines (61 loc) · 1.91 KB
/
Copy pathworker.go
File metadata and controls
65 lines (61 loc) · 1.91 KB
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
62
63
64
65
package durabletaskscheduler
import (
"context"
"io"
"github.com/microsoft/durabletask-go/api"
durabletaskclient "github.com/microsoft/durabletask-go/client"
"github.com/microsoft/durabletask-go/task"
"google.golang.org/grpc"
)
// NewWorker creates a DTS worker that owns and recreates its gRPC connections.
// The returned worker connects and performs its fail-fast Hello in Start or Run.
func NewWorker(
options *Options,
registry *task.TaskRegistry,
logger api.Logger,
workerOptions ...durabletaskclient.TaskHubGrpcWorkerOption,
) (*durabletaskclient.TaskHubGrpcWorker, error) {
prepared, err := prepareOptions(options)
if err != nil {
return nil, err
}
workerID := prepared.WorkerID
if workerID == "" {
workerID = defaultWorkerID()
}
factory := func(ctx context.Context) (grpc.ClientConnInterface, io.Closer, error) {
connection, err := connect(&prepared, workerRole, workerID)
if err != nil {
return nil, nil, err
}
return connection, connection, nil
}
configuredOptions := []durabletaskclient.TaskHubGrpcWorkerOption{
durabletaskclient.WithWorkerHelloTimeout(prepared.HelloTimeout),
durabletaskclient.WithWorkerDataConverter(prepared.DataConverter),
durabletaskclient.WithMaximumTimerInterval(prepared.MaximumTimerInterval),
durabletaskclient.WithMaxOrchestratorCompletionBytes(min(
prepared.MaxSendMessageSize,
durabletaskclient.DefaultMaxOrchestratorCompletionBytes,
)),
}
if prepared.LargePayloads != nil {
configuredOptions = append(
configuredOptions,
durabletaskclient.WithWorkerLargePayloads(prepared.LargePayloads),
)
}
if prepared.Versioning != nil {
configuredOptions = append(
configuredOptions,
durabletaskclient.WithTaskVersioning(*prepared.Versioning),
)
}
configuredOptions = append(configuredOptions, workerOptions...)
return durabletaskclient.NewTaskHubGrpcWorkerWithConnectionFactory(
factory,
registry,
logger,
configuredOptions...,
)
}