Reduce scheduler polling noise
Backend CI / Backend (push) Successful in 14m44s

This commit is contained in:
2026-05-21 00:56:43 +08:00
parent 509f9e0c71
commit 49b1ccc961
10 changed files with 615 additions and 21 deletions
@@ -67,6 +67,20 @@ type SchedulerRunFinish struct {
ErrorMessage *string
}
type SchedulerRunRecord struct {
JobKey string
TriggerID *int64
SchedulerInstanceID string
TriggerType string
ConfigVersion int
ConfigSnapshot map[string]any
Status string
Stats map[string]any
ErrorMessage *string
StartedAt time.Time
FinishedAt time.Time
}
type SchedulerTriggerCreate struct {
JobKey string
TriggerType string
@@ -332,6 +346,35 @@ func (r *SchedulerRepository) FinishRun(ctx context.Context, in SchedulerRunFini
`, in.RunID, in.Status, statsJSON, in.ErrorMessage))
}
func (r *SchedulerRepository) RecordRun(ctx context.Context, in SchedulerRunRecord) (*domain.SchedulerRun, error) {
configJSON, err := marshalSchedulerJSONMap(in.ConfigSnapshot)
if err != nil {
return nil, err
}
statsJSON, err := marshalSchedulerJSONMap(in.Stats)
if err != nil {
return nil, err
}
duration := in.FinishedAt.Sub(in.StartedAt).Milliseconds()
if duration < 0 {
duration = 0
}
return scanSchedulerRun(r.pool.QueryRow(ctx, `
INSERT INTO ops.scheduler_job_runs (
job_key, trigger_id, scheduler_instance_id, trigger_type,
status, config_version, config_snapshot, stats, error_message,
started_at, finished_at, duration_ms
)
VALUES ($1, $2, $3, $4, $5, $6, COALESCE($7::jsonb, '{}'::jsonb),
COALESCE($8::jsonb, '{}'::jsonb), $9, $10, $11, $12)
RETURNING id, job_key, trigger_id, scheduler_instance_id, trigger_type, status,
config_version, config_snapshot, stats, error_message, started_at,
finished_at, duration_ms
`, in.JobKey, in.TriggerID, nullableString(in.SchedulerInstanceID), in.TriggerType,
in.Status, in.ConfigVersion, configJSON, statsJSON, in.ErrorMessage,
in.StartedAt, in.FinishedAt, duration))
}
func (r *SchedulerRepository) ListRuns(ctx context.Context, f SchedulerRunFilter) ([]domain.SchedulerRun, int64, error) {
args := []any{}
where := "1=1"