-
Notifications
You must be signed in to change notification settings - Fork 7
/
example_temporal.pb.go
2033 lines (1822 loc) · 70.7 KB
/
example_temporal.pb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Code generated by protoc-gen-go_temporal. DO NOT EDIT.
// versions:
//
// protoc-gen-go_temporal 1.13.1-next (b7a15c407f9a9490670a48b7f288c936cdd1bc48)
// go go1.22.3
// protoc (unknown)
//
// source: example/v1/example.proto
package examplev1
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
expression "github.com/cludden/protoc-gen-go-temporal/pkg/expression"
helpers "github.com/cludden/protoc-gen-go-temporal/pkg/helpers"
scheme "github.com/cludden/protoc-gen-go-temporal/pkg/scheme"
testutil "github.com/cludden/protoc-gen-go-temporal/pkg/testutil"
gohomedir "github.com/mitchellh/go-homedir"
v2 "github.com/urfave/cli/v2"
v1 "go.temporal.io/api/enums/v1"
serviceerror "go.temporal.io/api/serviceerror"
v11 "go.temporal.io/api/update/v1"
activity "go.temporal.io/sdk/activity"
client "go.temporal.io/sdk/client"
temporal "go.temporal.io/sdk/temporal"
testsuite "go.temporal.io/sdk/testsuite"
worker "go.temporal.io/sdk/worker"
workflow "go.temporal.io/sdk/workflow"
protojson "google.golang.org/protobuf/encoding/protojson"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"log/slog"
"os"
"sort"
"strings"
"time"
)
// ExampleTaskQueue is the default task-queue for a example.v1.Example worker
const ExampleTaskQueue = "example-v1"
// example.v1.Example workflow names
const (
CreateFooWorkflowName = "example.v1.Example.CreateFoo"
)
// example.v1.Example workflow id expressions
var (
CreateFooIdexpression = expression.MustParseExpression("create-foo/${! name.slug() }")
)
// example.v1.Example activity names
const (
NotifyActivityName = "example.v1.Example.Notify"
)
// example.v1.Example query names
const (
GetFooProgressQueryName = "example.v1.Example.GetFooProgress"
)
// example.v1.Example signal names
const (
SetFooProgressSignalName = "example.v1.Example.SetFooProgress"
)
// example.v1.Example update names
const (
UpdateFooProgressUpdateName = "example.v1.Example.UpdateFooProgress"
)
// example.v1.Example update id expressions
var (
UpdateFooProgressIdexpression = expression.MustParseExpression("update-progress/${! progress.string() }")
)
// ExampleClient describes a client for a(n) example.v1.Example worker
type ExampleClient interface {
// CreateFoo creates a new foo operation
CreateFoo(ctx context.Context, req *CreateFooRequest, opts ...*CreateFooOptions) (*CreateFooResponse, error)
// CreateFooAsync starts a(n) example.v1.Example.CreateFoo workflow and returns a handle to the workflow run
CreateFooAsync(ctx context.Context, req *CreateFooRequest, opts ...*CreateFooOptions) (CreateFooRun, error)
// GetCreateFoo retrieves a handle to an existing example.v1.Example.CreateFoo workflow execution
GetCreateFoo(ctx context.Context, workflowID string, runID string) CreateFooRun
// CreateFooWithSetFooProgress sends a(n) example.v1.Example.SetFooProgress signal to a(n) example.v1.Example.CreateFoo workflow, starting it if necessary, and blocks until workflow completion
CreateFooWithSetFooProgress(ctx context.Context, req *CreateFooRequest, signal *SetFooProgressRequest, opts ...*CreateFooOptions) (*CreateFooResponse, error)
// CreateFooWithSetFooProgressAsync sends a(n) example.v1.Example.SetFooProgress signal to a(n) example.v1.Example.CreateFoo workflow, starting it if necessary, and returns a handle to the workflow execution
CreateFooWithSetFooProgressAsync(ctx context.Context, req *CreateFooRequest, signal *SetFooProgressRequest, opts ...*CreateFooOptions) (CreateFooRun, error)
// CancelWorkflow requests cancellation of an existing workflow execution
CancelWorkflow(ctx context.Context, workflowID string, runID string) error
// TerminateWorkflow an existing workflow execution
TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details ...interface{}) error
// GetFooProgress returns the status of a CreateFoo operation
GetFooProgress(ctx context.Context, workflowID string, runID string) (*GetFooProgressResponse, error)
// SetFooProgress sets the current status of a CreateFoo operation
SetFooProgress(ctx context.Context, workflowID string, runID string, signal *SetFooProgressRequest) error
// UpdateFooProgress sets the current status of a CreateFoo operation
UpdateFooProgress(ctx context.Context, workflowID string, runID string, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (*GetFooProgressResponse, error)
// UpdateFooProgressAsync starts a(n) example.v1.Example.UpdateFooProgress update and returns a handle to the workflow update
UpdateFooProgressAsync(ctx context.Context, workflowID string, runID string, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (UpdateFooProgressHandle, error)
// GetUpdateFooProgress retrieves a handle to an existing example.v1.Example.UpdateFooProgress update
GetUpdateFooProgress(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateFooProgressHandle, error)
}
// exampleClient implements a temporal client for a example.v1.Example service
type exampleClient struct {
client client.Client
log *slog.Logger
}
// NewExampleClient initializes a new example.v1.Example client
func NewExampleClient(c client.Client, options ...*exampleClientOptions) ExampleClient {
var cfg *exampleClientOptions
if len(options) > 0 {
cfg = options[0]
} else {
cfg = NewExampleClientOptions()
}
return &exampleClient{
client: c,
log: cfg.getLogger(),
}
}
// NewExampleClientWithOptions initializes a new Example client with the given options
func NewExampleClientWithOptions(c client.Client, opts client.Options, options ...*exampleClientOptions) (ExampleClient, error) {
var err error
c, err = client.NewClientFromExisting(c, opts)
if err != nil {
return nil, fmt.Errorf("error initializing client with options: %w", err)
}
var cfg *exampleClientOptions
if len(options) > 0 {
cfg = options[0]
} else {
cfg = NewExampleClientOptions()
}
return &exampleClient{
client: c,
log: cfg.getLogger(),
}, nil
}
// exampleClientOptions describes optional runtime configuration for a ExampleClient
type exampleClientOptions struct {
log *slog.Logger
}
// NewExampleClientOptions initializes a new exampleClientOptions value
func NewExampleClientOptions() *exampleClientOptions {
return &exampleClientOptions{}
}
// WithLogger can be used to override the default logger
func (opts *exampleClientOptions) WithLogger(l *slog.Logger) *exampleClientOptions {
if l != nil {
opts.log = l
}
return opts
}
// getLogger returns the configured logger, or the default logger
func (opts *exampleClientOptions) getLogger() *slog.Logger {
if opts != nil && opts.log != nil {
return opts.log
}
return slog.Default()
}
// CreateFoo creates a new foo operation
func (c *exampleClient) CreateFoo(ctx context.Context, req *CreateFooRequest, options ...*CreateFooOptions) (*CreateFooResponse, error) {
run, err := c.CreateFooAsync(ctx, req, options...)
if err != nil {
return nil, err
}
return run.Get(ctx)
}
// CreateFoo creates a new foo operation
func (c *exampleClient) CreateFooAsync(ctx context.Context, req *CreateFooRequest, options ...*CreateFooOptions) (CreateFooRun, error) {
var o *CreateFooOptions
if len(options) > 0 && options[0] != nil {
o = options[0]
} else {
o = NewCreateFooOptions()
}
opts, err := o.Build(req.ProtoReflect())
if err != nil {
return nil, fmt.Errorf("error initializing client.StartWorkflowOptions: %w", err)
}
run, err := c.client.ExecuteWorkflow(ctx, opts, CreateFooWorkflowName, req)
if err != nil {
return nil, err
}
if run == nil {
return nil, errors.New("execute workflow returned nil run")
}
return &createFooRun{
client: c,
run: run,
}, nil
}
// GetCreateFoo fetches an existing example.v1.Example.CreateFoo execution
func (c *exampleClient) GetCreateFoo(ctx context.Context, workflowID string, runID string) CreateFooRun {
return &createFooRun{
client: c,
run: c.client.GetWorkflow(ctx, workflowID, runID),
}
}
// CreateFooWithSetFooProgress starts a(n) example.v1.Example.CreateFoo workflow and sends a(n) example.v1.Example.SetFooProgress signal in a transaction
func (c *exampleClient) CreateFooWithSetFooProgress(ctx context.Context, req *CreateFooRequest, signal *SetFooProgressRequest, options ...*CreateFooOptions) (*CreateFooResponse, error) {
run, err := c.CreateFooWithSetFooProgressAsync(ctx, req, signal, options...)
if err != nil {
return nil, err
}
return run.Get(ctx)
}
// CreateFooWithSetFooProgressAsync starts a(n) example.v1.Example.CreateFoo workflow and sends a(n) example.v1.Example.SetFooProgress signal in a transaction
func (c *exampleClient) CreateFooWithSetFooProgressAsync(ctx context.Context, req *CreateFooRequest, signal *SetFooProgressRequest, options ...*CreateFooOptions) (CreateFooRun, error) {
var o *CreateFooOptions
if len(options) > 0 && options[0] != nil {
o = options[0]
} else {
o = NewCreateFooOptions()
}
opts, err := o.Build(req.ProtoReflect())
if err != nil {
return nil, fmt.Errorf("error initializing client.StartWorkflowOptions: %w", err)
}
run, err := c.client.SignalWithStartWorkflow(ctx, opts.ID, SetFooProgressSignalName, signal, opts, CreateFooWorkflowName, req)
if run == nil || err != nil {
return nil, err
}
return &createFooRun{
client: c,
run: run,
}, nil
}
// CancelWorkflow requests cancellation of an existing workflow execution
func (c *exampleClient) CancelWorkflow(ctx context.Context, workflowID string, runID string) error {
return c.client.CancelWorkflow(ctx, workflowID, runID)
}
// TerminateWorkflow terminates an existing workflow execution
func (c *exampleClient) TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details ...interface{}) error {
return c.client.TerminateWorkflow(ctx, workflowID, runID, reason, details...)
}
// GetFooProgress returns the status of a CreateFoo operation
func (c *exampleClient) GetFooProgress(ctx context.Context, workflowID string, runID string) (*GetFooProgressResponse, error) {
var resp GetFooProgressResponse
if val, err := c.client.QueryWorkflow(ctx, workflowID, runID, GetFooProgressQueryName); err != nil {
return nil, err
} else if err = val.Get(&resp); err != nil {
return nil, err
}
return &resp, nil
}
// SetFooProgress sets the current status of a CreateFoo operation
func (c *exampleClient) SetFooProgress(ctx context.Context, workflowID string, runID string, signal *SetFooProgressRequest) error {
return c.client.SignalWorkflow(ctx, workflowID, runID, SetFooProgressSignalName, signal)
}
// UpdateFooProgress sets the current status of a CreateFoo operation
func (c *exampleClient) UpdateFooProgress(ctx context.Context, workflowID string, runID string, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (*GetFooProgressResponse, error) {
// initialize update options
o := NewUpdateFooProgressOptions()
if len(opts) > 0 && opts[0].Options != nil {
o = opts[0]
}
// call sync update with UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED wait policy
handle, err := c.UpdateFooProgressAsync(ctx, workflowID, runID, req, o.WithWaitPolicy(v1.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED))
if err != nil {
return nil, err
}
// block on update completion
return handle.Get(ctx)
}
// UpdateFooProgress sets the current status of a CreateFoo operation
func (c *exampleClient) UpdateFooProgressAsync(ctx context.Context, workflowID string, runID string, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (UpdateFooProgressHandle, error) {
// initialize update options
var o *UpdateFooProgressOptions
if len(opts) > 0 && opts[0] != nil {
o = opts[0]
} else {
o = NewUpdateFooProgressOptions()
}
// build UpdateWorkflowWithOptionsRequest
options, err := o.Build(workflowID, runID, req)
if err != nil {
return nil, fmt.Errorf("error initializing UpdateWorkflowWithOptions: %w", err)
}
// update workflow
handle, err := c.client.UpdateWorkflowWithOptions(ctx, options)
if err != nil {
return nil, err
}
return &updateFooProgressHandle{client: c, handle: handle}, nil
}
// GetUpdateFooProgress retrieves a handle to an existing example.v1.Example.UpdateFooProgress update
func (c *exampleClient) GetUpdateFooProgress(ctx context.Context, req client.GetWorkflowUpdateHandleOptions) (UpdateFooProgressHandle, error) {
return &updateFooProgressHandle{
client: c,
handle: c.client.GetWorkflowUpdateHandle(req),
}, nil
}
// CreateFooOptions provides configuration for a example.v1.Example.CreateFoo workflow operation
type CreateFooOptions struct {
options client.StartWorkflowOptions
executionTimeout *time.Duration
id *string
idReusePolicy v1.WorkflowIdReusePolicy
retryPolicy *temporal.RetryPolicy
runTimeout *time.Duration
searchAttributes map[string]any
taskQueue *string
taskTimeout *time.Duration
}
// NewCreateFooOptions initializes a new CreateFooOptions value
func NewCreateFooOptions() *CreateFooOptions {
return &CreateFooOptions{}
}
// Build initializes a new go.temporal.io/sdk/client.StartWorkflowOptions value with defaults and overrides applied
func (o *CreateFooOptions) Build(req protoreflect.Message) (client.StartWorkflowOptions, error) {
opts := o.options
if v := o.id; v != nil {
opts.ID = *v
} else if opts.ID == "" {
id, err := expression.EvalExpression(CreateFooIdexpression, req)
if err != nil {
return opts, fmt.Errorf("error evaluating id expression for %q workflow: %w", CreateFooWorkflowName, err)
}
opts.ID = id
}
if v := o.idReusePolicy; v != v1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
opts.WorkflowIDReusePolicy = v
} else if opts.WorkflowIDReusePolicy == v1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
opts.WorkflowIDReusePolicy = v1.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
}
if v := o.taskQueue; v != nil {
opts.TaskQueue = *v
} else if opts.TaskQueue == "" {
opts.TaskQueue = ExampleTaskQueue
}
if v := o.retryPolicy; v != nil {
opts.RetryPolicy = v
}
if v := o.searchAttributes; v != nil {
opts.SearchAttributes = o.searchAttributes
}
if v := o.executionTimeout; v != nil {
opts.WorkflowExecutionTimeout = *v
} else if opts.WorkflowExecutionTimeout == 0 {
opts.WorkflowExecutionTimeout = 3600000000000 // 1 hour
}
if v := o.runTimeout; v != nil {
opts.WorkflowRunTimeout = *v
}
if v := o.taskTimeout; v != nil {
opts.WorkflowTaskTimeout = *v
}
return opts, nil
}
// WithStartWorkflowOptions sets the initial go.temporal.io/sdk/client.StartWorkflowOptions
func (o *CreateFooOptions) WithStartWorkflowOptions(options client.StartWorkflowOptions) *CreateFooOptions {
o.options = options
return o
}
// WithExecutionTimeout sets the WorkflowExecutionTimeout value
func (o *CreateFooOptions) WithExecutionTimeout(d time.Duration) *CreateFooOptions {
o.executionTimeout = &d
return o
}
// WithID sets the ID value
func (o *CreateFooOptions) WithID(id string) *CreateFooOptions {
o.id = &id
return o
}
// WithIDReusePolicy sets the WorkflowIDReusePolicy value
func (o *CreateFooOptions) WithIDReusePolicy(policy v1.WorkflowIdReusePolicy) *CreateFooOptions {
o.idReusePolicy = policy
return o
}
// WithRetryPolicy sets the RetryPolicy value
func (o *CreateFooOptions) WithRetryPolicy(policy *temporal.RetryPolicy) *CreateFooOptions {
o.retryPolicy = policy
return o
}
// WithRunTimeout sets the WorkflowRunTimeout value
func (o *CreateFooOptions) WithRunTimeout(d time.Duration) *CreateFooOptions {
o.runTimeout = &d
return o
}
// WithSearchAttributes sets the SearchAttributes value
func (o *CreateFooOptions) WithSearchAttributes(sa map[string]any) *CreateFooOptions {
o.searchAttributes = sa
return o
}
// WithTaskTimeout sets the WorkflowTaskTimeout value
func (o *CreateFooOptions) WithTaskTimeout(d time.Duration) *CreateFooOptions {
o.taskTimeout = &d
return o
}
// WithTaskQueue sets the TaskQueue value
func (o *CreateFooOptions) WithTaskQueue(tq string) *CreateFooOptions {
o.taskQueue = &tq
return o
}
// CreateFooRun describes a(n) example.v1.Example.CreateFoo workflow run
type CreateFooRun interface {
// ID returns the workflow ID
ID() string
// RunID returns the workflow instance ID
RunID() string
// Run returns the inner client.WorkflowRun
Run() client.WorkflowRun
// Get blocks until the workflow is complete and returns the result
Get(ctx context.Context) (*CreateFooResponse, error)
// Cancel requests cancellation of a workflow in execution, returning an error if applicable
Cancel(ctx context.Context) error
// Terminate terminates a workflow in execution, returning an error if applicable
Terminate(ctx context.Context, reason string, details ...interface{}) error
// GetFooProgress returns the status of a CreateFoo operation
GetFooProgress(ctx context.Context) (*GetFooProgressResponse, error)
// SetFooProgress sets the current status of a CreateFoo operation
SetFooProgress(ctx context.Context, req *SetFooProgressRequest) error
// UpdateFooProgress sets the current status of a CreateFoo operation
UpdateFooProgress(ctx context.Context, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (*GetFooProgressResponse, error)
// UpdateFooProgress sets the current status of a CreateFoo operation
UpdateFooProgressAsync(ctx context.Context, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (UpdateFooProgressHandle, error)
}
// createFooRun provides an internal implementation of a(n) CreateFooRunRun
type createFooRun struct {
client *exampleClient
run client.WorkflowRun
}
// ID returns the workflow ID
func (r *createFooRun) ID() string {
return r.run.GetID()
}
// Run returns the inner client.WorkflowRun
func (r *createFooRun) Run() client.WorkflowRun {
return r.run
}
// RunID returns the execution ID
func (r *createFooRun) RunID() string {
return r.run.GetRunID()
}
// Cancel requests cancellation of a workflow in execution, returning an error if applicable
func (r *createFooRun) Cancel(ctx context.Context) error {
return r.client.CancelWorkflow(ctx, r.ID(), r.RunID())
}
// Get blocks until the workflow is complete, returning the result if applicable
func (r *createFooRun) Get(ctx context.Context) (*CreateFooResponse, error) {
var resp CreateFooResponse
if err := r.run.Get(ctx, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// Terminate terminates a workflow in execution, returning an error if applicable
func (r *createFooRun) Terminate(ctx context.Context, reason string, details ...interface{}) error {
return r.client.TerminateWorkflow(ctx, r.ID(), r.RunID(), reason, details...)
}
// GetFooProgress returns the status of a CreateFoo operation
func (r *createFooRun) GetFooProgress(ctx context.Context) (*GetFooProgressResponse, error) {
return r.client.GetFooProgress(ctx, r.ID(), "")
}
// SetFooProgress sets the current status of a CreateFoo operation
func (r *createFooRun) SetFooProgress(ctx context.Context, req *SetFooProgressRequest) error {
return r.client.SetFooProgress(ctx, r.ID(), "", req)
}
// UpdateFooProgress sets the current status of a CreateFoo operation
func (r *createFooRun) UpdateFooProgress(ctx context.Context, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (*GetFooProgressResponse, error) {
return r.client.UpdateFooProgress(ctx, r.ID(), r.RunID(), req, opts...)
}
// UpdateFooProgress sets the current status of a CreateFoo operation
func (r *createFooRun) UpdateFooProgressAsync(ctx context.Context, req *SetFooProgressRequest, opts ...*UpdateFooProgressOptions) (UpdateFooProgressHandle, error) {
return r.client.UpdateFooProgressAsync(ctx, r.ID(), r.RunID(), req, opts...)
}
// UpdateFooProgressHandle describes a(n) example.v1.Example.UpdateFooProgress update handle
type UpdateFooProgressHandle interface {
// WorkflowID returns the workflow ID
WorkflowID() string
// RunID returns the workflow instance ID
RunID() string
// UpdateID returns the update ID
UpdateID() string
// Get blocks until the workflow is complete and returns the result
Get(ctx context.Context) (*GetFooProgressResponse, error)
}
// updateFooProgressHandle provides an internal implementation of a(n) UpdateFooProgressHandle
type updateFooProgressHandle struct {
client *exampleClient
handle client.WorkflowUpdateHandle
}
// WorkflowID returns the workflow ID
func (h *updateFooProgressHandle) WorkflowID() string {
return h.handle.WorkflowID()
}
// RunID returns the execution ID
func (h *updateFooProgressHandle) RunID() string {
return h.handle.RunID()
}
// UpdateID returns the update ID
func (h *updateFooProgressHandle) UpdateID() string {
return h.handle.UpdateID()
}
// Get blocks until the update wait policy is met, returning the result if applicable
func (h *updateFooProgressHandle) Get(ctx context.Context) (*GetFooProgressResponse, error) {
var resp GetFooProgressResponse
var err error
doneCh := make(chan struct{})
gctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
for {
var deadlineExceeded *serviceerror.DeadlineExceeded
if err = h.handle.Get(gctx, &resp); err != nil && ctx.Err() == nil && (errors.As(err, &deadlineExceeded) || strings.Contains(err.Error(), context.DeadlineExceeded.Error())) {
continue
}
break
}
close(doneCh)
}()
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-doneCh:
if err != nil {
return nil, err
}
return &resp, nil
}
}
// UpdateFooProgressOptions provides configuration for a example.v1.Example.UpdateFooProgress update operation
type UpdateFooProgressOptions struct {
Options *client.UpdateWorkflowWithOptionsRequest
id *string
waitPolicy v1.UpdateWorkflowExecutionLifecycleStage
}
// NewUpdateFooProgressOptions initializes a new UpdateFooProgressOptions value
func NewUpdateFooProgressOptions() *UpdateFooProgressOptions {
return &UpdateFooProgressOptions{Options: &client.UpdateWorkflowWithOptionsRequest{}}
}
// Build initializes a new client.UpdateWorkflowWithOptionsRequest with defaults and overrides applied
func (o *UpdateFooProgressOptions) Build(workflowID string, runID string, req *SetFooProgressRequest) (opts *client.UpdateWorkflowWithOptionsRequest, err error) {
// use user-provided UpdateWorkflowWithOptionsRequest if exists
if o.Options != nil {
opts = o.Options
} else {
opts = &client.UpdateWorkflowWithOptionsRequest{}
}
// set constants
opts.Args = []any{req}
opts.RunID = runID
opts.UpdateName = UpdateFooProgressUpdateName
opts.WorkflowID = workflowID
// set UpdateID
if v := o.id; v != nil {
opts.UpdateID = *v
} else if opts.UpdateID == "" {
id, err := expression.EvalExpression(UpdateFooProgressIdexpression, req.ProtoReflect())
if err != nil {
return nil, fmt.Errorf("error evaluating id expression for %q update: %w", UpdateFooProgressUpdateName, err)
}
opts.UpdateID = id
}
// set WaitPolicy
if v := o.waitPolicy; v != v1.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_UNSPECIFIED {
opts.WaitPolicy = &v11.WaitPolicy{LifecycleStage: v}
}
return opts, nil
}
// WithUpdateID sets the UpdateID
func (o *UpdateFooProgressOptions) WithUpdateID(id string) *UpdateFooProgressOptions {
o.id = &id
return o
}
// WithUpdateWorkflowOptions sets the initial client.UpdateWorkflowWithOptionsRequest
func (o *UpdateFooProgressOptions) WithUpdateWorkflowOptions(options client.UpdateWorkflowWithOptionsRequest) *UpdateFooProgressOptions {
o.Options = &options
return o
}
// WithWaitPolicy sets the WaitPolicy
func (o *UpdateFooProgressOptions) WithWaitPolicy(policy v1.UpdateWorkflowExecutionLifecycleStage) *UpdateFooProgressOptions {
o.waitPolicy = policy
return o
}
// Reference to generated workflow functions
var (
// CreateFoo creates a new foo operation
CreateFooFunction func(workflow.Context, *CreateFooRequest) (*CreateFooResponse, error)
)
// ExampleWorkflowFunctions describes a mockable dependency for inlining workflows within other workflows
type (
// ExampleWorkflowFunctions describes a mockable dependency for inlining workflows within other workflows
ExampleWorkflowFunctions interface {
// CreateFoo creates a new foo operation
CreateFoo(workflow.Context, *CreateFooRequest) (*CreateFooResponse, error)
}
// exampleWorkflowFunctions provides an internal ExampleWorkflowFunctions implementation
exampleWorkflowFunctions struct{}
)
func NewExampleWorkflowFunctions() ExampleWorkflowFunctions {
return &exampleWorkflowFunctions{}
}
// CreateFoo creates a new foo operation
func (f *exampleWorkflowFunctions) CreateFoo(ctx workflow.Context, req *CreateFooRequest) (*CreateFooResponse, error) {
if CreateFooFunction == nil {
return nil, errors.New("CreateFoo requires workflow registration via RegisterExampleWorkflows or RegisterCreateFooWorkflow")
}
return CreateFooFunction(ctx, req)
}
// ExampleWorkflows provides methods for initializing new example.v1.Example workflow values
type ExampleWorkflows interface {
// CreateFoo creates a new foo operation
CreateFoo(ctx workflow.Context, input *CreateFooWorkflowInput) (CreateFooWorkflow, error)
}
// RegisterExampleWorkflows registers example.v1.Example workflows with the given worker
func RegisterExampleWorkflows(r worker.WorkflowRegistry, workflows ExampleWorkflows) {
RegisterCreateFooWorkflow(r, workflows.CreateFoo)
}
// RegisterCreateFooWorkflow registers a example.v1.Example.CreateFoo workflow with the given worker
func RegisterCreateFooWorkflow(r worker.WorkflowRegistry, wf func(workflow.Context, *CreateFooWorkflowInput) (CreateFooWorkflow, error)) {
CreateFooFunction = buildCreateFoo(wf)
r.RegisterWorkflowWithOptions(CreateFooFunction, workflow.RegisterOptions{Name: CreateFooWorkflowName})
}
// buildCreateFoo converts a CreateFoo workflow struct into a valid workflow function
func buildCreateFoo(ctor func(workflow.Context, *CreateFooWorkflowInput) (CreateFooWorkflow, error)) func(workflow.Context, *CreateFooRequest) (*CreateFooResponse, error) {
return func(ctx workflow.Context, req *CreateFooRequest) (*CreateFooResponse, error) {
input := &CreateFooWorkflowInput{
Req: req,
SetFooProgress: &SetFooProgressSignal{
Channel: workflow.GetSignalChannel(ctx, SetFooProgressSignalName),
},
}
wf, err := ctor(ctx, input)
if err != nil {
return nil, err
}
if initializable, ok := wf.(helpers.Initializable); ok {
if err := initializable.Initialize(ctx); err != nil {
return nil, err
}
}
if err := workflow.SetQueryHandler(ctx, GetFooProgressQueryName, wf.GetFooProgress); err != nil {
return nil, err
}
{
opts := workflow.UpdateHandlerOptions{}
if err := workflow.SetUpdateHandlerWithOptions(ctx, UpdateFooProgressUpdateName, wf.UpdateFooProgress, opts); err != nil {
return nil, err
}
}
return wf.Execute(ctx)
}
}
// CreateFooWorkflowInput describes the input to a(n) example.v1.Example.CreateFoo workflow constructor
type CreateFooWorkflowInput struct {
Req *CreateFooRequest
SetFooProgress *SetFooProgressSignal
}
// CreateFoo creates a new foo operation
//
// workflow details: (name: "example.v1.Example.CreateFoo", id: "create-foo/${! name.slug() }")
type CreateFooWorkflow interface {
// Execute defines the entrypoint to a(n) example.v1.Example.CreateFoo workflow
Execute(ctx workflow.Context) (*CreateFooResponse, error)
// GetFooProgress returns the status of a CreateFoo operation
GetFooProgress() (*GetFooProgressResponse, error)
// UpdateFooProgress sets the current status of a CreateFoo operation
UpdateFooProgress(workflow.Context, *SetFooProgressRequest) (*GetFooProgressResponse, error)
}
// CreateFoo creates a new foo operation
func CreateFooChild(ctx workflow.Context, req *CreateFooRequest, options ...*CreateFooChildOptions) (*CreateFooResponse, error) {
childRun, err := CreateFooChildAsync(ctx, req, options...)
if err != nil {
return nil, err
}
return childRun.Get(ctx)
}
// CreateFoo creates a new foo operation
func CreateFooChildAsync(ctx workflow.Context, req *CreateFooRequest, options ...*CreateFooChildOptions) (*CreateFooChildRun, error) {
var o *CreateFooChildOptions
if len(options) > 0 && options[0] != nil {
o = options[0]
} else {
o = NewCreateFooChildOptions()
}
opts, err := o.Build(ctx, req.ProtoReflect())
if err != nil {
return nil, fmt.Errorf("error initializing workflow.ChildWorkflowOptions: %w", err)
}
ctx = workflow.WithChildOptions(ctx, opts)
return &CreateFooChildRun{Future: workflow.ExecuteChildWorkflow(ctx, CreateFooWorkflowName, req)}, nil
}
// CreateFooChildOptions provides configuration for a child example.v1.Example.CreateFoo workflow operation
type CreateFooChildOptions struct {
options workflow.ChildWorkflowOptions
executionTimeout *time.Duration
id *string
idReusePolicy v1.WorkflowIdReusePolicy
retryPolicy *temporal.RetryPolicy
runTimeout *time.Duration
searchAttributes map[string]any
taskQueue *string
taskTimeout *time.Duration
parentClosePolicy v1.ParentClosePolicy
waitForCancellation *bool
}
// NewCreateFooChildOptions initializes a new CreateFooChildOptions value
func NewCreateFooChildOptions() *CreateFooChildOptions {
return &CreateFooChildOptions{}
}
// Build initializes a new go.temporal.io/sdk/workflow.ChildWorkflowOptions value with defaults and overrides applied
func (o *CreateFooChildOptions) Build(ctx workflow.Context, req protoreflect.Message) (workflow.ChildWorkflowOptions, error) {
opts := o.options
if v := o.id; v != nil {
opts.WorkflowID = *v
} else if opts.WorkflowID == "" {
// wrap expression evaluation in local activity
// more info: https://cludden.github.io/protoc-gen-go-temporal/docs/guides/patches#pv_64-expression-evaluation-local-activity
if workflow.GetVersion(ctx, "cludden_protoc-gen-go-temporal_64_expression-evaluation-local-activity", workflow.DefaultVersion, 1) == 1 {
lao := workflow.GetLocalActivityOptions(ctx)
lao.ScheduleToCloseTimeout = time.Second * 10
if err := workflow.ExecuteLocalActivity(workflow.WithLocalActivityOptions(ctx, lao), func(ctx context.Context) (string, error) {
id, err := expression.EvalExpression(CreateFooIdexpression, req)
if err != nil {
return "", fmt.Errorf("error evaluating id expression for %q workflow: %w", CreateFooWorkflowName, err)
}
return id, nil
}).Get(ctx, &opts.WorkflowID); err != nil {
return opts, fmt.Errorf("error evaluating id expression for %q workflow: %w", CreateFooWorkflowName, err)
}
} else {
id, err := expression.EvalExpression(CreateFooIdexpression, req)
if err != nil {
return opts, fmt.Errorf("error evaluating id expression for %q workflow: %w", CreateFooWorkflowName, err)
}
opts.WorkflowID = id
}
}
if v := o.idReusePolicy; v != v1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
opts.WorkflowIDReusePolicy = v
} else if opts.WorkflowIDReusePolicy == v1.WORKFLOW_ID_REUSE_POLICY_UNSPECIFIED {
opts.WorkflowIDReusePolicy = v1.WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
}
if v := o.taskQueue; v != nil {
opts.TaskQueue = *v
} else if opts.TaskQueue == "" {
opts.TaskQueue = ExampleTaskQueue
}
if v := o.retryPolicy; v != nil {
opts.RetryPolicy = v
}
if v := o.searchAttributes; v != nil {
opts.SearchAttributes = o.searchAttributes
}
if v := o.executionTimeout; v != nil {
opts.WorkflowExecutionTimeout = *v
} else if opts.WorkflowExecutionTimeout == 0 {
opts.WorkflowExecutionTimeout = 3600000000000 // 1 hour
}
if v := o.runTimeout; v != nil {
opts.WorkflowRunTimeout = *v
}
if v := o.taskTimeout; v != nil {
opts.WorkflowTaskTimeout = *v
}
if v := o.parentClosePolicy; v != v1.PARENT_CLOSE_POLICY_UNSPECIFIED {
opts.ParentClosePolicy = v
}
if v := o.waitForCancellation; v != nil {
opts.WaitForCancellation = *v
}
return opts, nil
}
// WithChildWorkflowOptions sets the initial go.temporal.io/sdk/workflow.ChildWorkflowOptions
func (o *CreateFooChildOptions) WithChildWorkflowOptions(options workflow.ChildWorkflowOptions) *CreateFooChildOptions {
o.options = options
return o
}
// WithExecutionTimeout sets the WorkflowExecutionTimeout value
func (o *CreateFooChildOptions) WithExecutionTimeout(d time.Duration) *CreateFooChildOptions {
o.executionTimeout = &d
return o
}
// WithID sets the WorkflowID value
func (o *CreateFooChildOptions) WithID(id string) *CreateFooChildOptions {
o.id = &id
return o
}
// WithIDReusePolicy sets the WorkflowIDReusePolicy value
func (o *CreateFooChildOptions) WithIDReusePolicy(policy v1.WorkflowIdReusePolicy) *CreateFooChildOptions {
o.idReusePolicy = policy
return o
}
// WithParentClosePolicy sets the WorkflowIDReusePolicy value
func (o *CreateFooChildOptions) WithParentClosePolicy(policy v1.ParentClosePolicy) *CreateFooChildOptions {
o.parentClosePolicy = policy
return o
}
// WithRetryPolicy sets the RetryPolicy value
func (o *CreateFooChildOptions) WithRetryPolicy(policy *temporal.RetryPolicy) *CreateFooChildOptions {
o.retryPolicy = policy
return o
}
// WithRunTimeout sets the WorkflowRunTimeout value
func (o *CreateFooChildOptions) WithRunTimeout(d time.Duration) *CreateFooChildOptions {
o.runTimeout = &d
return o
}
// WithSearchAttributes sets the SearchAttributes value
func (o *CreateFooChildOptions) WithSearchAttributes(sa map[string]any) *CreateFooChildOptions {
o.searchAttributes = sa
return o
}
// WithTaskTimeout sets the WorkflowTaskTimeout value
func (o *CreateFooChildOptions) WithTaskTimeout(d time.Duration) *CreateFooChildOptions {
o.taskTimeout = &d
return o
}
// WithTaskQueue sets the TaskQueue value
func (o *CreateFooChildOptions) WithTaskQueue(tq string) *CreateFooChildOptions {
o.taskQueue = &tq
return o
}
// WithWaitForCancellation sets the WaitForCancellation value
func (o *CreateFooChildOptions) WithWaitForCancellation(wait bool) *CreateFooChildOptions {
o.waitForCancellation = &wait
return o
}
// CreateFooChildRun describes a child CreateFoo workflow run
type CreateFooChildRun struct {
Future workflow.ChildWorkflowFuture
}
// Get blocks until the workflow is completed, returning the response value
func (r *CreateFooChildRun) Get(ctx workflow.Context) (*CreateFooResponse, error) {
var resp CreateFooResponse
if err := r.Future.Get(ctx, &resp); err != nil {
return nil, err
}
return &resp, nil
}
// Select adds this completion to the selector. Callback can be nil.
func (r *CreateFooChildRun) Select(sel workflow.Selector, fn func(*CreateFooChildRun)) workflow.Selector {
return sel.AddFuture(r.Future, func(workflow.Future) {
if fn != nil {
fn(r)
}
})
}
// SelectStart adds waiting for start to the selector. Callback can be nil.
func (r *CreateFooChildRun) SelectStart(sel workflow.Selector, fn func(*CreateFooChildRun)) workflow.Selector {
return sel.AddFuture(r.Future.GetChildWorkflowExecution(), func(workflow.Future) {
if fn != nil {
fn(r)
}
})
}
// WaitStart waits for the child workflow to start
func (r *CreateFooChildRun) WaitStart(ctx workflow.Context) (*workflow.Execution, error) {
var exec workflow.Execution
if err := r.Future.GetChildWorkflowExecution().Get(ctx, &exec); err != nil {
return nil, err
}
return &exec, nil
}
// SetFooProgress sends a(n) "example.v1.Example.SetFooProgress" signal request to the child workflow
func (r *CreateFooChildRun) SetFooProgress(ctx workflow.Context, input *SetFooProgressRequest) error {
return r.SetFooProgressAsync(ctx, input).Get(ctx, nil)
}
// SetFooProgressAsync sends a(n) "example.v1.Example.SetFooProgress" signal request to the child workflow
func (r *CreateFooChildRun) SetFooProgressAsync(ctx workflow.Context, input *SetFooProgressRequest) workflow.Future {
return r.Future.SignalChildWorkflow(ctx, SetFooProgressSignalName, input)
}
// SetFooProgressSignal describes a(n) example.v1.Example.SetFooProgress signal
type SetFooProgressSignal struct {
Channel workflow.ReceiveChannel
}
// NewSetFooProgressSignal initializes a new example.v1.Example.SetFooProgress signal wrapper
func NewSetFooProgressSignal(ctx workflow.Context) *SetFooProgressSignal {
return &SetFooProgressSignal{Channel: workflow.GetSignalChannel(ctx, SetFooProgressSignalName)}
}
// Receive blocks until a(n) example.v1.Example.SetFooProgress signal is received
func (s *SetFooProgressSignal) Receive(ctx workflow.Context) (*SetFooProgressRequest, bool) {
var resp SetFooProgressRequest