work on daily aggregation with postgresql
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-11 10:48:32 +11:00
parent a0556e3ac8
commit b5bcea9da5

View File

@@ -3,6 +3,7 @@ package tasks
import ( import (
"context" "context"
"database/sql" "database/sql"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"os" "os"
@@ -406,13 +407,32 @@ LIMIT 1
} }
// Refine lifecycle with existing SQL helper to pick up first-after deletions. // Refine lifecycle with existing SQL helper to pick up first-after deletions.
if err := db.RefineCreationDeletionFromUnion(ctx, dbConn, summaryTable, unionQuery); err != nil { refineStart := time.Now()
c.Logger.Warn("failed to refine creation/deletion times", "error", err, "table", summaryTable) c.Logger.Debug("Refining creation/deletion times", "table", summaryTable)
refineCtx, cancelRefine := context.WithTimeout(ctx, 2*time.Minute)
defer cancelRefine()
if err := db.RefineCreationDeletionFromUnion(refineCtx, dbConn, summaryTable, unionQuery); err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(refineCtx.Err(), context.DeadlineExceeded) {
c.Logger.Warn("timed out refining creation/deletion times; continuing", "table", summaryTable, "timeout", "2m")
} else {
c.Logger.Warn("failed to refine creation/deletion times", "error", err, "table", summaryTable)
}
} else { } else {
c.Logger.Debug("refined creation/deletion times", "table", summaryTable) c.Logger.Debug("Refined creation/deletion times", "table", summaryTable, "duration", time.Since(refineStart))
} }
if err := db.UpdateSummaryPresenceByWindow(ctx, dbConn, summaryTable, dayStart.Unix(), dayEnd.Unix()); err != nil {
c.Logger.Warn("failed to update daily AvgIsPresent from lifecycle window (Go path)", "error", err, "table", summaryTable) presenceStart := time.Now()
c.Logger.Debug("Updating daily AvgIsPresent from lifecycle window", "table", summaryTable)
presenceCtx, cancelPresence := context.WithTimeout(ctx, 2*time.Minute)
defer cancelPresence()
if err := db.UpdateSummaryPresenceByWindow(presenceCtx, dbConn, summaryTable, dayStart.Unix(), dayEnd.Unix()); err != nil {
if errors.Is(err, context.DeadlineExceeded) || errors.Is(presenceCtx.Err(), context.DeadlineExceeded) {
c.Logger.Warn("timed out updating daily AvgIsPresent from lifecycle window; continuing", "table", summaryTable, "timeout", "2m")
} else {
c.Logger.Warn("failed to update daily AvgIsPresent from lifecycle window (Go path)", "error", err, "table", summaryTable)
}
} else {
c.Logger.Debug("Updated daily AvgIsPresent from lifecycle window", "table", summaryTable, "duration", time.Since(presenceStart))
} }
analyzeStart := time.Now() analyzeStart := time.Now()