use scheduler

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-11-16 20:04:43 +03:00
parent ad6e4fed09
commit 31528740dc

View File

@ -41,17 +41,22 @@ func main() {
} }
l.Info(ctx, "scheduler: create") l.Info(ctx, "scheduler: create")
s, err := scheduler.NewScheduler() sch, err := scheduler.NewScheduler()
if err != nil { if err != nil {
l.Fatal(ctx, "failed to create scheduler", err) l.Fatal(ctx, "failed to create scheduler", err)
} }
l.Info(ctx, "scheduler: created") l.Info(ctx, "scheduler: created")
l.Info(ctx, "scheduler: try to start") 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.Fatal(ctx, "failed to start scheduler", err)
} }
l.Info(ctx, "scheduler: starting") 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) clients := make(map[string]client.Client)
gcli := grpccli.NewClient( gcli := grpccli.NewClient(
@ -117,7 +122,7 @@ func main() {
treq := c.NewRequest(pkg, svc+"."+mth, req) 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} labels := []string{"check", check.Name, "task", task.Name, "service", svc, "endpoint", mth}
m.Counter(semconv.ClientRequestInflight, labels...).Inc() m.Counter(semconv.ClientRequestInflight, labels...).Inc()
ts := time.Now() ts := time.Now()
@ -140,4 +145,5 @@ func main() {
} }
<-ctx.Done() <-ctx.Done()
l.Info(ctx, "exiting")
} }