perf(scheduler): harden jobs for scalable execution

This commit is contained in:
2026-05-20 12:19:27 +08:00
parent 4b09a34748
commit 5fb9d0b0dd
23 changed files with 887 additions and 147 deletions
@@ -0,0 +1,36 @@
package scheduler
import (
"strings"
"testing"
)
func TestBatchDeleteSQLUsesBoundedSkipLockedDelete(t *testing.T) {
sql := batchDeleteSQL("monitoring_collect_tasks", "id", "business_date < $1::date", "business_date ASC, id ASC")
for _, want := range []string{
"LIMIT $2",
"FOR UPDATE SKIP LOCKED",
"DELETE FROM monitoring_collect_tasks t",
"USING doomed",
"WHERE t.id = doomed.id",
} {
if !strings.Contains(sql, want) {
t.Fatalf("batchDeleteSQL missing %q in SQL:\n%s", want, sql)
}
}
if strings.Contains(sql, "COUNT(*) FROM monitoring_collect_tasks") {
t.Fatalf("batchDeleteSQL must not count full candidate set:\n%s", sql)
}
}
func TestBatchProbeSQLCapsDryRunProbe(t *testing.T) {
sql := batchProbeSQL("monitoring_collect_tasks", "id", "business_date < $1::date", "business_date ASC, id ASC")
if !strings.Contains(sql, "LIMIT $2") {
t.Fatalf("batchProbeSQL should cap dry-run probe:\n%s", sql)
}
if !strings.Contains(sql, "SELECT COUNT(*)::bigint") {
t.Fatalf("batchProbeSQL should count only the limited candidate subquery:\n%s", sql)
}
}