File tree Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Expand file tree Collapse file tree 2 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,12 @@ func main() {
48
48
49
49
wo := worker .DefaultOptions
50
50
wo .WorkflowExecutorCacheSize = * cacheSize
51
+
52
+ if * b == "redis" {
53
+ wo .ActivityPollingInterval = 0
54
+ wo .WorkflowPollingInterval = 0
55
+ }
56
+
51
57
w := worker .New (ba , & wo )
52
58
53
59
w .RegisterWorkflow (Root )
@@ -150,7 +156,10 @@ func getBackend(b string, opt ...backend.BackendOption) backend.Backend {
150
156
ReadTimeout : time .Second * 30 ,
151
157
})
152
158
153
- rclient .FlushAll (context .Background ()).Result ()
159
+ _ , err := rclient .FlushAll (context .Background ()).Result ()
160
+ if err != nil {
161
+ panic (err )
162
+ }
154
163
155
164
b , err := redis .NewRedisBackend (rclient , redis .WithBackendOptions (opt ... ))
156
165
if err != nil {
Original file line number Diff line number Diff line change @@ -80,10 +80,20 @@ func (w *Worker[Task, TaskResult]) WaitForCompletion() error {
80
80
func (w * Worker [Task , TaskResult ]) poller (ctx context.Context ) {
81
81
defer w .pollersWg .Done ()
82
82
83
- ticker := time .NewTicker (w .options .PollingInterval )
84
- defer ticker .Stop ()
83
+ var ticker * time.Ticker
84
+
85
+ if w .options .PollingInterval > 0 {
86
+ ticker = time .NewTicker (w .options .PollingInterval )
87
+ defer ticker .Stop ()
88
+ }
85
89
86
90
for {
91
+ select {
92
+ case <- ctx .Done ():
93
+ return
94
+ default :
95
+ }
96
+
87
97
task , err := w .poll (ctx , 30 * time .Second )
88
98
if err != nil {
89
99
w .logger .ErrorContext (ctx , "error polling task" , "error" , err )
@@ -92,10 +102,12 @@ func (w *Worker[Task, TaskResult]) poller(ctx context.Context) {
92
102
continue // check for new tasks right away
93
103
}
94
104
95
- select {
96
- case <- ticker .C :
97
- case <- ctx .Done ():
98
- return
105
+ if w .options .PollingInterval > 0 {
106
+ select {
107
+ case <- ticker .C :
108
+ case <- ctx .Done ():
109
+ return
110
+ }
99
111
}
100
112
}
101
113
}
You can’t perform that action at this time.
0 commit comments