From 31528740dc93b5cff63d42dd7bfd5ce81e667c92 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sat, 16 Nov 2024 20:04:43 +0300 Subject: [PATCH] use scheduler Signed-off-by: Vasiliy Tolstov --- cmd/servicechecker/main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/servicechecker/main.go b/cmd/servicechecker/main.go index 2904b19..52265ea 100644 --- a/cmd/servicechecker/main.go +++ b/cmd/servicechecker/main.go @@ -41,17 +41,22 @@ func main() { } l.Info(ctx, "scheduler: create") - s, err := scheduler.NewScheduler() + sch, err := scheduler.NewScheduler() if err != nil { l.Fatal(ctx, "failed to create scheduler", err) } l.Info(ctx, "scheduler: created") l.Info(ctx, "scheduler: try to start") - if err = s.Start(); err != nil { + if err = sch.Start(); err != nil { l.Fatal(ctx, "failed to start scheduler", err) } l.Info(ctx, "scheduler: starting") + defer func() { + if err = sch.Stop(); err != nil { + l.Error(ctx, "failed to stop scheduler", err) + } + }() clients := make(map[string]client.Client) gcli := grpccli.NewClient( @@ -117,7 +122,7 @@ func main() { treq := c.NewRequest(pkg, svc+"."+mth, req) - s.NewJob(time.Duration(check.Interval), func() { + sch.NewJob(time.Duration(check.Interval), func() { labels := []string{"check", check.Name, "task", task.Name, "service", svc, "endpoint", mth} m.Counter(semconv.ClientRequestInflight, labels...).Inc() ts := time.Now() @@ -140,4 +145,5 @@ func main() { } <-ctx.Done() + l.Info(ctx, "exiting") }