From 9a604a50b945b7199f48586289ad79b47e720731 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Sat, 3 Oct 2020 12:57:02 +0300 Subject: [PATCH] [#70] cmd/neofs-node: Start asynchronous workers on app launch Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config.go | 2 ++ cmd/neofs-node/main.go | 1 + cmd/neofs-node/worker.go | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 cmd/neofs-node/worker.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index eab122b9df..d2b008011b 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -105,6 +105,8 @@ type cfg struct { cfgObject cfgObject profiler profiler.Profiler + + workers []worker } type cfgGRPC struct { diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index b496a85161..f3ab711042 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -44,6 +44,7 @@ func bootUp(c *cfg) { serveProfiler(c) serveGRPC(c) bootstrapNode(c) + startWorkers(c) } func wait(c *cfg) { diff --git a/cmd/neofs-node/worker.go b/cmd/neofs-node/worker.go new file mode 100644 index 0000000000..3d66cfc280 --- /dev/null +++ b/cmd/neofs-node/worker.go @@ -0,0 +1,20 @@ +package main + +import ( + "context" +) + +type worker interface { + Run(context.Context) +} + +func startWorkers(c *cfg) { + for _, wrk := range c.workers { + c.wg.Add(1) + + go func() { + wrk.Run(c.ctx) + c.wg.Done() + }() + } +}