All checks were successful
release-tag / release-image (push) Successful in 2m43s
68 lines
2.7 KiB
Go
68 lines
2.7 KiB
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/local/glpi-neural-brain/internal/model"
|
|
)
|
|
|
|
func (e *Engine) controllerAutomationLoop(ctx context.Context) {
|
|
if e.SourceInbox == nil {
|
|
return
|
|
}
|
|
ticker := time.NewTicker(time.Minute)
|
|
defer ticker.Stop()
|
|
run := func() {
|
|
recovery, err := e.SourceInbox.RunControllerHealthAutomation(ctx)
|
|
if err == nil {
|
|
for _, job := range recovery {
|
|
e.Broker.Publish(model.Activity{Type: "controller.job.queued", Source: "brain", Phase: "controller-recovery", Message: "Controller-Recovery wurde wegen eines ungesunden Containers eingeplant", Strength: .82, Metadata: map[string]any{"job_id": job.ID, "kind": job.Kind, "profile_id": job.ProfileID, "autonomous": true}})
|
|
}
|
|
}
|
|
tests, err := e.SourceInbox.RunControllerScheduledTests(ctx)
|
|
if err == nil {
|
|
for _, job := range tests {
|
|
e.Broker.Publish(model.Activity{Type: "controller.job.queued", Source: "brain", Phase: "controller-test", Message: "Freigegebener Compose-Smoke-Test wurde eingeplant", Strength: .58, Metadata: map[string]any{"job_id": job.ID, "kind": job.Kind, "profile_id": job.ProfileID, "autonomous": true}})
|
|
}
|
|
}
|
|
}
|
|
run()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
run()
|
|
}
|
|
}
|
|
}
|
|
|
|
func (e *Engine) queueControllerEvidenceProbe(ctx context.Context, result model.ResearchResult, nodeIDs []string) {
|
|
if e.SourceInbox == nil {
|
|
return
|
|
}
|
|
quality := strings.ToLower(strings.TrimSpace(result.SourceQuality))
|
|
if quality != "primary" && quality != "authoritative" && result.SourceQualityScore < .80 {
|
|
return
|
|
}
|
|
job, ok, err := e.SourceInbox.QueueAutonomousEvidenceProbe(ctx, result.URL, result.Title, result.SourceQuality, nodeIDs)
|
|
if err != nil || !ok {
|
|
return
|
|
}
|
|
e.Broker.Publish(model.Activity{Type: "controller.job.queued", Source: "brain", Phase: "evidence-validation", NodeIDs: nodeIDs, Message: "Unabhängige Docker-Sandbox prüft den akzeptierten Webbeleg ein zweites Mal", Strength: .62, Metadata: map[string]any{"job_id": job.ID, "kind": job.Kind, "profile_id": job.ProfileID, "url": result.URL, "source_quality": result.SourceQuality, "autonomous": true}})
|
|
}
|
|
|
|
func (e *Engine) requestControllerComputeCapacity(ctx context.Context, computeKind string) bool {
|
|
if e.SourceInbox == nil {
|
|
return false
|
|
}
|
|
job, ok, err := e.SourceInbox.QueueComputeCapacityController(ctx, computeKind)
|
|
if err != nil || !ok {
|
|
return false
|
|
}
|
|
e.Broker.Publish(model.Activity{Type: "controller.job.queued", Source: "brain", Phase: "compute-capacity", Message: "Controller startet freigegebene Compose-Compute-Kapazität", Strength: .66, Metadata: map[string]any{"job_id": job.ID, "profile_id": job.ProfileID, "compute_kind": computeKind, "autonomous": true}})
|
|
return true
|
|
}
|