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:
parent
3493c18841
commit
363ebed728
1 changed files with 19 additions and 0 deletions
|
|
@ -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
|
||||
|
|
@ -42,6 +48,13 @@ type checkerEngine struct {
|
|||
entryStore DiscoveryEntryStorage
|
||||
obsRefStore DiscoveryObservationStorage
|
||||
relatedLookup checkerPkg.RelatedObservationLookup
|
||||
|
||||
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. Passing nil
|
||||
|
|
@ -145,6 +158,12 @@ func (e *checkerEngine) RunExecution(ctx context.Context, exec *happydns.Executi
|
|||
log.Printf("CheckerEngine: failed to update execution: %v", err)
|
||||
}
|
||||
|
||||
// Fire notification callback (runs synchronously within the caller's goroutine
|
||||
// so that shutdown can wait for it to complete).
|
||||
if e.onComplete != nil {
|
||||
e.onComplete(exec, eval)
|
||||
}
|
||||
|
||||
return eval, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue