diff options
author | Valery Piashchynski <[email protected]> | 2021-11-04 18:36:09 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-11-04 18:36:09 +0300 |
commit | 7fc77a67f0b94edcbe18b23bde01d8de37b1d16d (patch) | |
tree | 30e79fd7734099f4b7f46eefc62e736c53f54b28 /worker_watcher/worker_watcher.go | |
parent | c1c16ddb8717af5b19f45118e615241ac14a54d6 (diff) |
Make a `Destroy` context useful
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'worker_watcher/worker_watcher.go')
-rwxr-xr-x | worker_watcher/worker_watcher.go | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/worker_watcher/worker_watcher.go b/worker_watcher/worker_watcher.go index 949958ac..544c9789 100755 --- a/worker_watcher/worker_watcher.go +++ b/worker_watcher/worker_watcher.go @@ -227,7 +227,7 @@ func (ww *workerWatcher) Release(w worker.BaseProcess) { } // Destroy all underlying container (but let them complete the task) -func (ww *workerWatcher) Destroy(_ context.Context) { +func (ww *workerWatcher) Destroy(ctx context.Context) { // destroy container, we don't use ww mutex here, since we should be able to push worker ww.Lock() // do not release new workers @@ -237,7 +237,7 @@ func (ww *workerWatcher) Destroy(_ context.Context) { ww.events.Unsubscribe(ww.eventsID) tt := time.NewTicker(time.Millisecond * 100) defer tt.Stop() - for { //nolint:gosimple + for { select { case <-tt.C: ww.Lock() @@ -254,6 +254,14 @@ func (ww *workerWatcher) Destroy(_ context.Context) { _ = ww.workers[i].Kill() } return + case <-ctx.Done(): + // kill workers + ww.Lock() + for i := 0; i < len(ww.workers); i++ { + ww.workers[i].State().Set(worker.StateDestroyed) + _ = ww.workers[i].Kill() + } + ww.Unlock() } } } |