@@ -3,6 +3,7 @@ package local
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "strconv"
6
7
"sync"
7
8
8
9
"github.com/dapr/durabletask-go/api"
@@ -33,26 +34,24 @@ func NewTasksBackend() *TasksBackend {
33
34
}
34
35
35
36
func (be * TasksBackend ) CompleteActivityTask (ctx context.Context , response * protos.ActivityResponse ) error {
36
- key := backend .GetActivityExecutionKey (response .GetInstanceId (), response .GetTaskId ())
37
- if be .deletePendingActivityTask (key , response ) {
37
+ if be .deletePendingActivityTask (response .GetInstanceId (), response .GetTaskId (), response ) {
38
38
return nil
39
39
}
40
- return fmt .Errorf ("unknown instance ID/task ID combo: %s" , key )
40
+ return fmt .Errorf ("unknown instance ID/task ID combo: %s" , response . GetInstanceId () + "/" + strconv . FormatInt ( int64 ( response . GetTaskId ()), 10 ) )
41
41
}
42
42
43
43
func (be * TasksBackend ) CancelActivityTask (ctx context.Context , instanceID api.InstanceID , taskID int32 ) error {
44
- key := backend .GetActivityExecutionKey (string (instanceID ), taskID )
45
- if be .deletePendingActivityTask (key , nil ) {
44
+ if be .deletePendingActivityTask (string (instanceID ), taskID , nil ) {
46
45
return nil
47
46
}
48
- return fmt .Errorf ("unknown instance ID/task ID combo: %s" , key )
47
+ return fmt .Errorf ("unknown instance ID/task ID combo: %s" , string ( instanceID ) + "/" + strconv . FormatInt ( int64 ( taskID ), 10 ) )
49
48
}
50
49
51
50
func (be * TasksBackend ) WaitForActivityCompletion (ctx context.Context , request * protos.ActivityRequest ) (* protos.ActivityResponse , error ) {
52
- key := backend .GetActivityExecutionKey (string ( request .GetOrchestrationInstance ().GetInstanceId () ), request .GetTaskId ())
51
+ key := backend .GetActivityExecutionKey (request .GetOrchestrationInstance ().GetInstanceId (), request .GetTaskId ())
53
52
pending := & pendingActivity {
54
53
response : nil ,
55
- complete : make (chan struct {}),
54
+ complete : make (chan struct {}, 1 ),
56
55
}
57
56
be .pendingActivities .Store (key , pending )
58
57
@@ -68,14 +67,14 @@ func (be *TasksBackend) WaitForActivityCompletion(ctx context.Context, request *
68
67
}
69
68
70
69
func (be * TasksBackend ) CompleteOrchestratorTask (ctx context.Context , response * protos.OrchestratorResponse ) error {
71
- if be .deletePendingOrchestrator (api . InstanceID ( response .GetInstanceId () ), response ) {
70
+ if be .deletePendingOrchestrator (response .GetInstanceId (), response ) {
72
71
return nil
73
72
}
74
73
return fmt .Errorf ("unknown instance ID: %s" , response .GetInstanceId ())
75
74
}
76
75
77
76
func (be * TasksBackend ) CancelOrchestratorTask (ctx context.Context , instanceID api.InstanceID ) error {
78
- if be .deletePendingOrchestrator (instanceID , nil ) {
77
+ if be .deletePendingOrchestrator (string ( instanceID ) , nil ) {
79
78
return nil
80
79
}
81
80
return fmt .Errorf ("unknown instance ID: %s" , instanceID )
@@ -84,7 +83,7 @@ func (be *TasksBackend) CancelOrchestratorTask(ctx context.Context, instanceID a
84
83
func (be * TasksBackend ) WaitForOrchestratorCompletion (ctx context.Context , request * protos.OrchestratorRequest ) (* protos.OrchestratorResponse , error ) {
85
84
pending := & pendingOrchestrator {
86
85
response : nil ,
87
- complete : make (chan struct {}),
86
+ complete : make (chan struct {}, 1 ),
88
87
}
89
88
be .pendingOrchestrators .Store (request .GetInstanceId (), pending )
90
89
@@ -99,7 +98,8 @@ func (be *TasksBackend) WaitForOrchestratorCompletion(ctx context.Context, reque
99
98
}
100
99
}
101
100
102
- func (be * TasksBackend ) deletePendingActivityTask (key string , res * protos.ActivityResponse ) bool {
101
+ func (be * TasksBackend ) deletePendingActivityTask (iid string , taskID int32 , res * protos.ActivityResponse ) bool {
102
+ key := backend .GetActivityExecutionKey (iid , taskID )
103
103
p , ok := be .pendingActivities .LoadAndDelete (key )
104
104
if ! ok {
105
105
return false
@@ -112,8 +112,8 @@ func (be *TasksBackend) deletePendingActivityTask(key string, res *protos.Activi
112
112
return true
113
113
}
114
114
115
- func (be * TasksBackend ) deletePendingOrchestrator (iid api. InstanceID , res * protos.OrchestratorResponse ) bool {
116
- p , ok := be .pendingOrchestrators .LoadAndDelete (iid )
115
+ func (be * TasksBackend ) deletePendingOrchestrator (instanceID string , res * protos.OrchestratorResponse ) bool {
116
+ p , ok := be .pendingOrchestrators .LoadAndDelete (instanceID )
117
117
if ! ok {
118
118
return false
119
119
}
0 commit comments