-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement batch insertion for drift analysis projects and add background job supervision #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
76f8f3f
c95c033
4df9c8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package observability | ||
|
|
||
| import ( | ||
| "context" | ||
| "runtime/debug" | ||
| "time" | ||
|
|
||
| "github.com/gofiber/fiber/v3/log" | ||
| "go.opentelemetry.io/otel/attribute" | ||
| "go.opentelemetry.io/otel/metric" | ||
| ) | ||
|
|
||
| const superviseRestartBackoff = time.Second | ||
|
|
||
| // SuperviseLoop runs fn in a panic-safe loop until ctx is cancelled. | ||
| func SuperviseLoop(ctx context.Context, name string, fn func(context.Context)) { | ||
| for { | ||
| if ctx.Err() != nil { | ||
| log.Infof("supervised loop %q exiting: %v", name, ctx.Err()) | ||
| return | ||
| } | ||
| runOnce(ctx, name, fn) | ||
| select { | ||
| case <-ctx.Done(): | ||
| log.Infof("supervised loop %q exiting: %v", name, ctx.Err()) | ||
| return | ||
| case <-time.After(superviseRestartBackoff): | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func runOnce(ctx context.Context, name string, fn func(context.Context)) { | ||
| defer func() { | ||
| if r := recover(); r != nil { | ||
| log.Errorf("supervised loop %q panicked: %v\n%s", name, r, debug.Stack()) | ||
| if m := GetMetrics(); m != nil && m.BgJobPanicsTotal != nil { | ||
| m.BgJobPanicsTotal.Add(ctx, 1, metric.WithAttributes(attribute.String("job", name))) | ||
| } | ||
| } | ||
| }() | ||
| fn(ctx) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.