summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-08-28 22:51:04 +0300
committerValery Piashchynski <[email protected]>2021-08-28 22:51:04 +0300
commit22e17a99fe2087f9c11a438e877afbac0096c052 (patch)
treea9d9c31c9677f4e29fe96b627e45481a87b67f20 /pkg
parentfb356081dcaea81952e2019502c0216af7d10c7d (diff)
Re-allocate a worker with allocate frequency (every 500ms per try)
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'pkg')
-rwxr-xr-xpkg/worker_watcher/worker_watcher.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/pkg/worker_watcher/worker_watcher.go b/pkg/worker_watcher/worker_watcher.go
index 8ab9f664..83f8e627 100755
--- a/pkg/worker_watcher/worker_watcher.go
+++ b/pkg/worker_watcher/worker_watcher.go
@@ -151,15 +151,20 @@ func (ww *workerWatcher) Allocate() error {
return errors.E(op, errors.WorkerAllocate, err)
}
+ // every half of a second
+ allocateFreq := time.NewTicker(time.Millisecond * 500)
+
tt := time.After(ww.allocateTimeout)
for {
select {
case <-tt:
// reduce number of workers
atomic.AddUint64(ww.numWorkers, ^uint64(0))
+ allocateFreq.Stop()
// timeout exceed, worker can't be allocated
return errors.E(op, errors.WorkerAllocate, err)
- default:
+
+ case <-allocateFreq.C:
sw, err = ww.allocator()
if err != nil {
// log incident
@@ -172,6 +177,7 @@ func (ww *workerWatcher) Allocate() error {
}
// reallocated
+ allocateFreq.Stop()
goto done
}
}