checker: add execution callback for notification integration

Add ExecutionCallbackSetter interface and onComplete field to the
checker engine. After a successful execution, the callback is fired
asynchronously so it never blocks the checker pipeline.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
nemunaire 2026-04-11 08:49:29 +07:00
commit f17b046e1b

View file

@ -32,6 +32,12 @@ import (
"git.happydns.org/happyDomain/model"
)
// ExecutionCallbackSetter is implemented by checker engines that support
// notification callbacks after execution completion.
type ExecutionCallbackSetter interface {
SetExecutionCallback(func(*happydns.Execution, *happydns.CheckEvaluation))
}
// checkerEngine implements the happydns.CheckerEngine interface.
type checkerEngine struct {
optionsUC *CheckerOptionsUsecase
@ -39,6 +45,13 @@ type checkerEngine struct {
execStore ExecutionStorage
snapStore ObservationSnapshotStorage
cacheStore ObservationCacheStorage
onComplete func(exec *happydns.Execution, eval *happydns.CheckEvaluation)
}
// SetExecutionCallback registers a callback invoked after each successful execution.
func (e *checkerEngine) SetExecutionCallback(cb func(*happydns.Execution, *happydns.CheckEvaluation)) {
e.onComplete = cb
}
// NewCheckerEngine creates a new CheckerEngine implementation.
@ -135,6 +148,11 @@ func (e *checkerEngine) RunExecution(ctx context.Context, exec *happydns.Executi
log.Printf("CheckerEngine: failed to update execution: %v", err)
}
// Fire notification callback asynchronously.
if e.onComplete != nil {
go e.onComplete(exec, eval)
}
return eval, nil
}