@@ -3,6 +3,7 @@ package aggregatedpool
33import (
44 "context"
55 "fmt"
6+ "strconv"
67 "sync"
78 "sync/atomic"
89 "time"
@@ -15,6 +16,7 @@ import (
1516 "github.com/temporalio/roadrunner-temporal/v5/queue"
1617 "github.com/temporalio/roadrunner-temporal/v5/registry"
1718 commonpb "go.temporal.io/api/common/v1"
19+ enumspb "go.temporal.io/api/enums/v1"
1820 temporalClient "go.temporal.io/sdk/client"
1921 bindings "go.temporal.io/sdk/internalbindings"
2022 "go.uber.org/zap"
@@ -131,23 +133,139 @@ func (wp *Workflow) Execute(env bindings.WorkflowEnvironment, header *commonpb.H
131133 env .RegisterQueryHandler (wp .handleQuery )
132134 env .RegisterUpdateHandler (wp .handleUpdate )
133135
134- var lastCompletion = bindings .GetLastCompletionResult (env )
135- var lastCompletionOffset = 0
136+ // check if we have some TSA
137+ tsa := env .TypedSearchAttributes ()
138+ // start workflow command
139+ stwfcmd := internal.StartWorkflow {
140+ Info : env .WorkflowInfo (),
141+ }
142+
143+ // search attributes types are:
144+ /*
145+ INDEXED_VALUE_TYPE_TEXT IndexedValueType = 1
146+ INDEXED_VALUE_TYPE_KEYWORD IndexedValueType = 2
147+ INDEXED_VALUE_TYPE_INT IndexedValueType = 3
148+ INDEXED_VALUE_TYPE_DOUBLE IndexedValueType = 4
149+ INDEXED_VALUE_TYPE_BOOL IndexedValueType = 5
150+ INDEXED_VALUE_TYPE_DATETIME IndexedValueType = 6
151+ INDEXED_VALUE_TYPE_KEYWORD_LIST IndexedValueType = 7
152+
153+ */
154+ // only process if there're values, obviously
155+ if tsa .Size () > 0 {
156+ untuped := tsa .GetUntypedValues ()
157+ tsaParsed := make (map [string ]* internal.TypedSearchAttribute , tsa .Size ())
158+ for k , v := range untuped {
159+ vt := k .GetValueType ()
160+ switch vt {
161+ // just for the linters, should be never reached
162+ case enumspb .INDEXED_VALUE_TYPE_UNSPECIFIED :
163+ continue
164+ case enumspb .INDEXED_VALUE_TYPE_TEXT :
165+ str , ok := v .(string )
166+ if ! ok {
167+ wp .log .Warn ("typed search attribute found, but it is not a string" , zap .String ("key" , k .GetName ()))
168+ continue
169+ }
170+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
171+ Type : internal .StringType ,
172+ Value : str ,
173+ }
174+ case enumspb .INDEXED_VALUE_TYPE_KEYWORD :
175+ str , ok := v .(string )
176+ if ! ok {
177+ wp .log .Warn ("typed search attribute found, but it is not a string[keyword]" , zap .String ("key" , k .GetName ()))
178+ continue
179+ }
180+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
181+ Type : internal .KeywordType ,
182+ Value : str ,
183+ }
184+ case enumspb .INDEXED_VALUE_TYPE_INT :
185+ switch tt := v .(type ) {
186+ case int :
187+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
188+ Type : internal .IntType ,
189+ Value : tt ,
190+ }
191+ case int64 :
192+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
193+ Type : internal .IntType ,
194+ Value : tt ,
195+ }
196+ case string :
197+ res , err := strconv .Atoi (tt )
198+ if err != nil {
199+ wp .log .Warn ("typed search attribute found, but it is not an int" , zap .Error (err ), zap .String ("key" , k .GetName ()))
200+ continue
201+ }
202+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
203+ Type : internal .IntType ,
204+ Value : res ,
205+ }
206+ default :
207+ wp .log .Warn ("typed search attribute found, but it is not an int" , zap .String ("key" , k .GetName ()))
208+ continue
209+ }
210+ case enumspb .INDEXED_VALUE_TYPE_DOUBLE :
211+ str , ok := v .(float64 )
212+ if ! ok {
213+ wp .log .Warn ("typed search attribute found, but it is not a float64" , zap .String ("key" , k .GetName ()))
214+ continue
215+ }
216+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
217+ Type : internal .FloatType ,
218+ Value : str ,
219+ }
220+ case enumspb .INDEXED_VALUE_TYPE_BOOL :
221+ str , ok := v .(bool )
222+ if ! ok {
223+ wp .log .Warn ("typed search attribute found, but it is not a bool" , zap .String ("key" , k .GetName ()))
224+ continue
225+ }
226+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
227+ Type : internal .BoolType ,
228+ Value : str ,
229+ }
230+ case enumspb .INDEXED_VALUE_TYPE_DATETIME :
231+ str , ok := v .(time.Time )
232+ if ! ok {
233+ wp .log .Warn ("typed search attribute found, but it is not a datetime" , zap .String ("key" , k .GetName ()))
234+ continue
235+ }
236+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
237+ Type : internal .DatetimeType ,
238+ Value : str .Format (time .RFC3339 ),
239+ }
240+ case enumspb .INDEXED_VALUE_TYPE_KEYWORD_LIST :
241+ str , ok := v .([]string )
242+ if ! ok {
243+ wp .log .Warn ("typed search attribute found, but it is not a []string" , zap .String ("key" , k .GetName ()))
244+ continue
245+ }
246+ tsaParsed [k .GetName ()] = & internal.TypedSearchAttribute {
247+ Type : internal .KeywordListType ,
248+ Value : str ,
249+ }
250+ }
251+ }
136252
253+ // set typed search attributes
254+ stwfcmd .SearchAttributes = tsaParsed
255+ }
256+
257+ var lastCompletion = bindings .GetLastCompletionResult (env )
137258 if lastCompletion != nil && len (lastCompletion .Payloads ) != 0 {
138259 if input == nil {
139260 input = & commonpb.Payloads {Payloads : []* commonpb.Payload {}}
140261 }
141262
142263 input .Payloads = append (input .Payloads , lastCompletion .Payloads ... )
143- lastCompletionOffset = len (lastCompletion .Payloads )
264+ stwfcmd . LastCompletion = len (lastCompletion .Payloads )
144265 }
145266
146267 wp .mq .PushCommand (
147- internal.StartWorkflow {
148- Info : env .WorkflowInfo (),
149- LastCompletion : lastCompletionOffset ,
150- },
268+ stwfcmd ,
151269 input ,
152270 wp .header ,
153271 )
0 commit comments