@@ -2,32 +2,25 @@ package workflow
2
2
3
3
import (
4
4
"context"
5
- "crypto/tls"
6
5
"errors"
7
6
"fmt"
8
- "github.com/dapr/go-sdk/workflow/internal"
9
- "google.golang.org/grpc/credentials"
7
+ dapr "github.com/dapr/go-sdk/client"
8
+ "github.com/microsoft/durabletask-go/backend"
9
+ "github.com/microsoft/durabletask-go/client"
10
+ "github.com/microsoft/durabletask-go/task"
10
11
"log"
11
12
"reflect"
12
13
"runtime"
13
14
"strings"
14
15
"sync"
15
- "time"
16
-
17
- "github.com/microsoft/durabletask-go/backend"
18
- "github.com/microsoft/durabletask-go/client"
19
- "github.com/microsoft/durabletask-go/task"
20
- "google.golang.org/grpc"
21
- "google.golang.org/grpc/credentials/insecure"
22
16
)
23
17
24
18
type WorkflowRuntime struct {
25
19
tasks * task.TaskRegistry
26
20
client * client.TaskHubGrpcClient
27
21
28
- mutex sync.Mutex // TODO: implement
29
- quit chan bool
30
- cancel context.CancelFunc
22
+ mutex sync.Mutex // TODO: implement
23
+ quit chan bool
31
24
}
32
25
33
26
type Workflow func (ctx * Context ) (any , error )
@@ -39,28 +32,17 @@ func NewRuntime(address string) (*WorkflowRuntime, error) {
39
32
return & WorkflowRuntime {}, errors .New ("no address provided" )
40
33
}
41
34
42
- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 ) // TODO: add timeout option
35
+ ctx , cancel := context .WithCancel (context .Background ())
36
+ defer cancel ()
43
37
44
- connectionOptions := []grpc.DialOption {
45
- grpc .WithUserAgent (internal .UserAgent ()),
46
- grpc .WithBlock (),
47
- }
38
+ daprClient , err := dapr .NewClientWithAddressContext (ctx , address )
48
39
49
- parsedAddress , err := internal .ParseGRPCEndpoint (address )
50
-
51
- if parsedAddress .TLS {
52
- connectionOptions = append (connectionOptions , grpc .WithTransportCredentials (credentials .NewTLS (new (tls.Config ))))
53
- } else {
54
- connectionOptions = append (connectionOptions , grpc .WithTransportCredentials (insecure .NewCredentials ()))
40
+ if err != nil {
41
+ return & WorkflowRuntime {}, fmt .Errorf ("failed to create runtime - dapr client failed: %v" , err )
55
42
}
56
43
57
- clientConn , err := grpc .DialContext (
58
- ctx ,
59
- parsedAddress .Target ,
60
- connectionOptions ... ,
61
- )
44
+ clientConn := daprClient .GrpcClientConn ()
62
45
63
- cancel ()
64
46
if err != nil {
65
47
return & WorkflowRuntime {}, fmt .Errorf ("failed to create runtime - grpc connection failed: %v" , err )
66
48
}
@@ -69,7 +51,6 @@ func NewRuntime(address string) (*WorkflowRuntime, error) {
69
51
tasks : task .NewTaskRegistry (),
70
52
client : client .NewTaskHubGrpcClient (clientConn , backend .DefaultLogger ()),
71
53
quit : make (chan bool ),
72
- cancel : cancel ,
73
54
}, nil
74
55
}
75
56
@@ -145,8 +126,6 @@ func (wr *WorkflowRuntime) Start() error {
145
126
}
146
127
147
128
func (wr * WorkflowRuntime ) Shutdown () error {
148
- // cancel grpc context
149
- wr .cancel ()
150
129
// send close signal
151
130
wr .quit <- true
152
131
log .Println ("work item listener shutdown signal sent" )
0 commit comments