diff options
author | Valery Piashchynski <[email protected]> | 2021-11-04 08:45:32 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2021-11-04 08:45:32 -0700 |
commit | a18e8eb737d686a4adf8d965aaf1c5a936c6f8b0 (patch) | |
tree | 23b3ad2014c7b0d373dfe8b63d9fac98991e53d3 | |
parent | c1c16ddb8717af5b19f45118e615241ac14a54d6 (diff) | |
parent | 9b3bf26e4f3cce0fab1b7971dc83d315230fabd0 (diff) |
[#848]: feat(worker_watcher): make a ww's `Destroy` context useful
[#848]: feat(worker_watcher): make a ww's `Destroy` context useful
-rw-r--r-- | .github/workflows/linters.yml | 2 | ||||
-rwxr-xr-x | worker_watcher/worker_watcher.go | 12 |
2 files changed, 11 insertions, 3 deletions
diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 99cca039..0c7620d8 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -13,6 +13,6 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v2 # Action page: <https://github.com/golangci/golangci-lint-action> with: - version: v1.42 # without patch version + version: v1.43 # without patch version only-new-issues: false # show only new issues if it's a pull request args: --timeout=10m 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() } } } |