make inbound check optional

This commit is contained in:
ayurishchev committed 2026-08-21 11:25:52 +03:00
1 parent 67adc6670e
commit c630f13c57
11 files changed
+203 -45

No files matched your search

+41 -3
View File
@@ -207,11 +207,14 @@ func (o *Orchestrator) MarkSiteComplete(ctx context.Context, ipID int64, siteInd
// every source, or hit the checking-window deadline, into aggregation.
func (o *Orchestrator) sweepCheckingWindow(ctx context.Context) error {
deadline := db.Now().Add(-time.Duration(o.Cfg.CheckingWindowSeconds) * time.Second)
ready, err := o.DB.ListReadyToAggregate(ctx, deadline)
checking, err := o.DB.ListChecking(ctx)
if err != nil {
return fmt.Errorf("list ready to aggregate: %w", err)
return fmt.Errorf("list checking: %w", err)
}
for _, item := range ready {
for _, item := range checking {
if !o.isReadyToAggregate(item, deadline) {
continue
}
if err := o.aggregateAndRelease(ctx, item); err != nil {
o.Log.Error("aggregate and release", "ip_id", item.ID, "err", err)
}
@@ -219,6 +222,41 @@ func (o *Orchestrator) sweepCheckingWindow(ctx context.Context) error {
return nil
}
// isReadyToAggregate reports whether an in-progress IP has either finished
// reporting from every source it's actually expecting, or hit the
// checking-window deadline. Which inbound sources it's expecting is driven
// entirely by o.Sites — inbound checks are optional: an empty (or
// partial) `sites` config in control-api.yaml means this IP is ready as
// soon as egress completes (or after the corresponding subset of
// siteN_complete flags), with no need to wait on a prober that will never
// exist. This is what makes inbound checks genuinely opt-in rather than a
// hardcoded expectation of exactly three sites.
func (o *Orchestrator) isReadyToAggregate(item db.IPQueueItem, deadline time.Time) bool {
if item.AssignedAt != nil && item.AssignedAt.Before(deadline) {
return true
}
if !item.EgressComplete {
return false
}
for _, s := range o.Sites {
switch s.Index {
case 1:
if !item.Site1Complete {
return false
}
case 2:
if !item.Site2Complete {
return false
}
case 3:
if !item.Site3Complete {
return false
}
}
}
return true
}
func (o *Orchestrator) aggregateAndRelease(ctx context.Context, item db.IPQueueItem) error {
if err := o.DB.SetAggregating(ctx, item.ID); err != nil {
return err