forked from TrueCloudLab/frostfs-node
[#1868] Reload config for pprof and metrics on SIGHUP
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
2b755ddb12
commit
22f3c7d080
12 changed files with 345 additions and 172 deletions
|
@ -4,31 +4,46 @@ import (
|
|||
"context"
|
||||
)
|
||||
|
||||
type worker interface {
|
||||
Run(context.Context)
|
||||
}
|
||||
|
||||
type workerFromFunc struct {
|
||||
fn func(context.Context)
|
||||
type worker struct {
|
||||
name string
|
||||
fn func(context.Context)
|
||||
}
|
||||
|
||||
func newWorkerFromFunc(fn func(ctx context.Context)) worker {
|
||||
return &workerFromFunc{
|
||||
return worker{
|
||||
fn: fn,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *workerFromFunc) Run(ctx context.Context) {
|
||||
w.fn(ctx)
|
||||
}
|
||||
|
||||
func startWorkers(c *cfg) {
|
||||
for _, wrk := range c.workers {
|
||||
c.wg.Add(1)
|
||||
|
||||
go func(w worker) {
|
||||
w.Run(c.ctx)
|
||||
c.wg.Done()
|
||||
}(wrk)
|
||||
startWorker(c, wrk)
|
||||
}
|
||||
}
|
||||
|
||||
func startWorker(c *cfg, wrk worker) {
|
||||
c.wg.Add(1)
|
||||
|
||||
go func(w worker) {
|
||||
w.fn(c.ctx)
|
||||
c.wg.Done()
|
||||
}(wrk)
|
||||
}
|
||||
|
||||
func delWorker(c *cfg, name string) {
|
||||
for i, worker := range c.workers {
|
||||
if worker.name == name {
|
||||
c.workers = append(c.workers[:i], c.workers[i+1:]...)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getWorker(c *cfg, name string) *worker {
|
||||
for _, wrk := range c.workers {
|
||||
if wrk.name == name {
|
||||
return &wrk
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue