feat(api): add /v1/maintenance policies and run endpoints

OpenAPI, httpapi CRUD/run/dry-run, job maintenance_policy_run и audit с policy_id.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Denozordec
2026-06-12 13:23:10 +07:00
co-authored by Cursor
parent 6510a9ca22
commit f548d0671f
8 changed files with 653 additions and 15 deletions
+3 -11
View File
@@ -8,14 +8,12 @@ import (
"sync"
"time"
"evobgp/internal/jobs"
"github.com/robfig/cron/v3"
)
// StartScheduler enqueues maintenance_policy_run jobs when cron schedules match.
func StartScheduler(ctx context.Context, provider *ConfigProvider, reg *jobs.Registry, tick time.Duration) {
if provider == nil || reg == nil {
func StartScheduler(ctx context.Context, provider *ConfigProvider, enqueue func(policyID string, dryRun bool, idempotencyKey string), tick time.Duration) {
if provider == nil || enqueue == nil {
return
}
if tick <= 0 {
@@ -76,14 +74,8 @@ func StartScheduler(ctx context.Context, provider *ConfigProvider, reg *jobs.Reg
continue
}
lastFired[p.ID] = next
dry := p.DryRunEnabled
idem := fmt.Sprintf("maint-%s-%d", p.ID, slot)
key := idem
_, _, _ = reg.Enqueue("", "maintenance_policy_run", &key, nil, map[string]any{
"policy_id": p.ID,
"dry_run": dry,
"trigger": "scheduler",
})
enqueue(p.ID, p.DryRunEnabled, idem)
}
mu.Unlock()
}