@@ -30,16 +30,16 @@ const (
30
30
31
31
// GetWorkflowContexts implements tinkerbell.GetWorkflowContexts
32
32
func (s * server ) GetWorkflowContexts (req * pb.WorkflowContextRequest , stream pb.WorkflowService_GetWorkflowContextsServer ) error {
33
- wfs , err := getWorkflowsForWorker (s .db , req .WorkerId )
33
+ wfs , err := getWorkflowsForWorker (stream . Context (), s .db , req .WorkerId )
34
34
if err != nil {
35
35
return err
36
36
}
37
37
for _ , wf := range wfs {
38
- wfContext , err := s .db .GetWorkflowContexts (context . Background (), wf )
38
+ wfContext , err := s .db .GetWorkflowContexts (stream . Context (), wf )
39
39
if err != nil {
40
40
return status .Errorf (codes .Aborted , err .Error ())
41
41
}
42
- if isApplicableToSend (context . Background (), s .logger , wfContext , req .WorkerId , s .db ) {
42
+ if isApplicableToSend (stream . Context (), s .logger , wfContext , req .WorkerId , s .db ) {
43
43
if err := stream .Send (wfContext ); err != nil {
44
44
return err
45
45
}
@@ -49,16 +49,16 @@ func (s *server) GetWorkflowContexts(req *pb.WorkflowContextRequest, stream pb.W
49
49
}
50
50
51
51
// GetWorkflowContextList implements tinkerbell.GetWorkflowContextList
52
- func (s * server ) GetWorkflowContextList (context context.Context , req * pb.WorkflowContextRequest ) (* pb.WorkflowContextList , error ) {
53
- wfs , err := getWorkflowsForWorker (s .db , req .WorkerId )
52
+ func (s * server ) GetWorkflowContextList (ctx context.Context , req * pb.WorkflowContextRequest ) (* pb.WorkflowContextList , error ) {
53
+ wfs , err := getWorkflowsForWorker (ctx , s .db , req .WorkerId )
54
54
if err != nil {
55
55
return nil , err
56
56
}
57
57
58
58
if wfs != nil {
59
59
wfContexts := []* pb.WorkflowContext {}
60
60
for _ , wf := range wfs {
61
- wfContext , err := s .db .GetWorkflowContexts (context , wf )
61
+ wfContext , err := s .db .GetWorkflowContexts (ctx , wf )
62
62
if err != nil {
63
63
return nil , status .Errorf (codes .Aborted , err .Error ())
64
64
}
@@ -72,16 +72,16 @@ func (s *server) GetWorkflowContextList(context context.Context, req *pb.Workflo
72
72
}
73
73
74
74
// GetWorkflowActions implements tinkerbell.GetWorkflowActions
75
- func (s * server ) GetWorkflowActions (context context.Context , req * pb.WorkflowActionsRequest ) (* pb.WorkflowActionList , error ) {
75
+ func (s * server ) GetWorkflowActions (ctx context.Context , req * pb.WorkflowActionsRequest ) (* pb.WorkflowActionList , error ) {
76
76
wfID := req .GetWorkflowId ()
77
77
if wfID == "" {
78
78
return nil , status .Errorf (codes .InvalidArgument , errInvalidWorkflowId )
79
79
}
80
- return getWorkflowActions (context , s .db , wfID )
80
+ return getWorkflowActions (ctx , s .db , wfID )
81
81
}
82
82
83
83
// ReportActionStatus implements tinkerbell.ReportActionStatus
84
- func (s * server ) ReportActionStatus (context context.Context , req * pb.WorkflowActionStatus ) (* pb.Empty , error ) {
84
+ func (s * server ) ReportActionStatus (ctx context.Context , req * pb.WorkflowActionStatus ) (* pb.Empty , error ) {
85
85
wfID := req .GetWorkflowId ()
86
86
if wfID == "" {
87
87
return nil , status .Errorf (codes .InvalidArgument , errInvalidWorkflowId )
@@ -96,11 +96,11 @@ func (s *server) ReportActionStatus(context context.Context, req *pb.WorkflowAct
96
96
l := s .logger .With ("actionName" , req .GetActionName (), "workflowID" , req .GetWorkflowId ())
97
97
l .Info (fmt .Sprintf (msgReceivedStatus , req .GetActionStatus ()))
98
98
99
- wfContext , err := s .db .GetWorkflowContexts (context , wfID )
99
+ wfContext , err := s .db .GetWorkflowContexts (ctx , wfID )
100
100
if err != nil {
101
101
return nil , status .Errorf (codes .Aborted , err .Error ())
102
102
}
103
- wfActions , err := s .db .GetWorkflowActions (context , wfID )
103
+ wfActions , err := s .db .GetWorkflowActions (ctx , wfID )
104
104
if err != nil {
105
105
return nil , status .Errorf (codes .Aborted , err .Error ())
106
106
}
@@ -123,14 +123,14 @@ func (s *server) ReportActionStatus(context context.Context, req *pb.WorkflowAct
123
123
wfContext .CurrentAction = req .GetActionName ()
124
124
wfContext .CurrentActionState = req .GetActionStatus ()
125
125
wfContext .CurrentActionIndex = actionIndex
126
- err = s .db .UpdateWorkflowState (context , wfContext )
126
+ err = s .db .UpdateWorkflowState (ctx , wfContext )
127
127
if err != nil {
128
128
return & pb.Empty {}, status .Errorf (codes .Aborted , err .Error ())
129
129
}
130
130
131
131
// TODO the below "time" would be a part of the request which is coming form worker.
132
132
time := time .Now ()
133
- err = s .db .InsertIntoWorkflowEventTable (context , req , time )
133
+ err = s .db .InsertIntoWorkflowEventTable (ctx , req , time )
134
134
if err != nil {
135
135
return & pb.Empty {}, status .Error (codes .Aborted , err .Error ())
136
136
}
@@ -149,7 +149,7 @@ func (s *server) ReportActionStatus(context context.Context, req *pb.WorkflowAct
149
149
}
150
150
151
151
// UpdateWorkflowData updates workflow ephemeral data
152
- func (s * server ) UpdateWorkflowData (context context.Context , req * pb.UpdateWorkflowDataRequest ) (* pb.Empty , error ) {
152
+ func (s * server ) UpdateWorkflowData (ctx context.Context , req * pb.UpdateWorkflowDataRequest ) (* pb.Empty , error ) {
153
153
wfID := req .GetWorkflowId ()
154
154
if wfID == "" {
155
155
return & pb.Empty {}, status .Errorf (codes .InvalidArgument , errInvalidWorkflowId )
@@ -158,57 +158,57 @@ func (s *server) UpdateWorkflowData(context context.Context, req *pb.UpdateWorkf
158
158
if ! ok {
159
159
workflowData [wfID ] = 1
160
160
}
161
- err := s .db .InsertIntoWfDataTable (context , req )
161
+ err := s .db .InsertIntoWfDataTable (ctx , req )
162
162
if err != nil {
163
163
return & pb.Empty {}, status .Errorf (codes .Aborted , err .Error ())
164
164
}
165
165
return & pb.Empty {}, nil
166
166
}
167
167
168
168
// GetWorkflowData gets the ephemeral data for a workflow
169
- func (s * server ) GetWorkflowData (context context.Context , req * pb.GetWorkflowDataRequest ) (* pb.GetWorkflowDataResponse , error ) {
169
+ func (s * server ) GetWorkflowData (ctx context.Context , req * pb.GetWorkflowDataRequest ) (* pb.GetWorkflowDataResponse , error ) {
170
170
wfID := req .GetWorkflowId ()
171
171
if wfID == "" {
172
172
return & pb.GetWorkflowDataResponse {Data : []byte ("" )}, status .Errorf (codes .InvalidArgument , errInvalidWorkflowId )
173
173
}
174
- data , err := s .db .GetfromWfDataTable (context , req )
174
+ data , err := s .db .GetfromWfDataTable (ctx , req )
175
175
if err != nil {
176
176
return & pb.GetWorkflowDataResponse {Data : []byte ("" )}, status .Errorf (codes .Aborted , err .Error ())
177
177
}
178
178
return & pb.GetWorkflowDataResponse {Data : data }, nil
179
179
}
180
180
181
181
// GetWorkflowMetadata returns metadata wrt to the ephemeral data of a workflow
182
- func (s * server ) GetWorkflowMetadata (context context.Context , req * pb.GetWorkflowDataRequest ) (* pb.GetWorkflowDataResponse , error ) {
183
- data , err := s .db .GetWorkflowMetadata (context , req )
182
+ func (s * server ) GetWorkflowMetadata (ctx context.Context , req * pb.GetWorkflowDataRequest ) (* pb.GetWorkflowDataResponse , error ) {
183
+ data , err := s .db .GetWorkflowMetadata (ctx , req )
184
184
if err != nil {
185
185
return & pb.GetWorkflowDataResponse {Data : []byte ("" )}, status .Errorf (codes .Aborted , err .Error ())
186
186
}
187
187
return & pb.GetWorkflowDataResponse {Data : data }, nil
188
188
}
189
189
190
190
// GetWorkflowDataVersion returns the latest version of data for a workflow
191
- func (s * server ) GetWorkflowDataVersion (context context.Context , req * pb.GetWorkflowDataRequest ) (* pb.GetWorkflowDataResponse , error ) {
192
- version , err := s .db .GetWorkflowDataVersion (context , req .WorkflowId )
191
+ func (s * server ) GetWorkflowDataVersion (ctx context.Context , req * pb.GetWorkflowDataRequest ) (* pb.GetWorkflowDataResponse , error ) {
192
+ version , err := s .db .GetWorkflowDataVersion (ctx , req .WorkflowId )
193
193
if err != nil {
194
194
return & pb.GetWorkflowDataResponse {Version : version }, status .Errorf (codes .Aborted , err .Error ())
195
195
}
196
196
return & pb.GetWorkflowDataResponse {Version : version }, nil
197
197
}
198
198
199
- func getWorkflowsForWorker (db db.Database , id string ) ([]string , error ) {
199
+ func getWorkflowsForWorker (ctx context. Context , db db.Database , id string ) ([]string , error ) {
200
200
if id == "" {
201
201
return nil , status .Errorf (codes .InvalidArgument , errInvalidWorkerID )
202
202
}
203
- wfs , err := db .GetWorkflowsForWorker (id )
203
+ wfs , err := db .GetWorkflowsForWorker (ctx , id )
204
204
if err != nil {
205
205
return nil , status .Errorf (codes .Aborted , err .Error ())
206
206
}
207
207
return wfs , nil
208
208
}
209
209
210
- func getWorkflowActions (context context.Context , db db.Database , wfID string ) (* pb.WorkflowActionList , error ) {
211
- actions , err := db .GetWorkflowActions (context , wfID )
210
+ func getWorkflowActions (ctx context.Context , db db.Database , wfID string ) (* pb.WorkflowActionList , error ) {
211
+ actions , err := db .GetWorkflowActions (ctx , wfID )
212
212
if err != nil {
213
213
return nil , status .Errorf (codes .Aborted , errInvalidWorkflowId )
214
214
}
@@ -217,12 +217,12 @@ func getWorkflowActions(context context.Context, db db.Database, wfID string) (*
217
217
218
218
// isApplicableToSend checks if a particular workflow context is applicable or if it is needed to
219
219
// be sent to a worker based on the state of the current action and the targeted workerID
220
- func isApplicableToSend (context context.Context , logger log.Logger , wfContext * pb.WorkflowContext , workerID string , db db.Database ) bool {
220
+ func isApplicableToSend (ctx context.Context , logger log.Logger , wfContext * pb.WorkflowContext , workerID string , db db.Database ) bool {
221
221
if wfContext .GetCurrentActionState () == pb .State_STATE_FAILED ||
222
222
wfContext .GetCurrentActionState () == pb .State_STATE_TIMEOUT {
223
223
return false
224
224
}
225
- actions , err := getWorkflowActions (context , db , wfContext .GetWorkflowId ())
225
+ actions , err := getWorkflowActions (ctx , db , wfContext .GetWorkflowId ())
226
226
if err != nil {
227
227
return false
228
228
}
0 commit comments