@@ -2,32 +2,25 @@ package workflow
22
33import (
44 "context"
5- "crypto/tls"
65 "errors"
76 "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"
1011 "log"
1112 "reflect"
1213 "runtime"
1314 "strings"
1415 "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"
2216)
2317
2418type WorkflowRuntime struct {
2519 tasks * task.TaskRegistry
2620 client * client.TaskHubGrpcClient
2721
28- mutex sync.Mutex // TODO: implement
29- quit chan bool
30- cancel context.CancelFunc
22+ mutex sync.Mutex // TODO: implement
23+ quit chan bool
3124}
3225
3326type Workflow func (ctx * Context ) (any , error )
@@ -39,28 +32,17 @@ func NewRuntime(address string) (*WorkflowRuntime, error) {
3932 return & WorkflowRuntime {}, errors .New ("no address provided" )
4033 }
4134
42- ctx , cancel := context .WithTimeout (context .Background (), time .Second * 5 ) // TODO: add timeout option
35+ ctx , cancel := context .WithCancel (context .Background ())
36+ defer cancel ()
4337
44- connectionOptions := []grpc.DialOption {
45- grpc .WithUserAgent (internal .UserAgent ()),
46- grpc .WithBlock (),
47- }
38+ daprClient , err := dapr .NewClientWithAddressContext (ctx , address )
4839
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 )
5542 }
5643
57- clientConn , err := grpc .DialContext (
58- ctx ,
59- parsedAddress .Target ,
60- connectionOptions ... ,
61- )
44+ clientConn := daprClient .GrpcClientConn ()
6245
63- cancel ()
6446 if err != nil {
6547 return & WorkflowRuntime {}, fmt .Errorf ("failed to create runtime - grpc connection failed: %v" , err )
6648 }
@@ -69,7 +51,6 @@ func NewRuntime(address string) (*WorkflowRuntime, error) {
6951 tasks : task .NewTaskRegistry (),
7052 client : client .NewTaskHubGrpcClient (clientConn , backend .DefaultLogger ()),
7153 quit : make (chan bool ),
72- cancel : cancel ,
7354 }, nil
7455}
7556
@@ -145,8 +126,6 @@ func (wr *WorkflowRuntime) Start() error {
145126}
146127
147128func (wr * WorkflowRuntime ) Shutdown () error {
148- // cancel grpc context
149- wr .cancel ()
150129 // send close signal
151130 wr .quit <- true
152131 log .Println ("work item listener shutdown signal sent" )
0 commit comments