refactor aggregate jobs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-01-15 09:04:52 +11:00
parent 8b2c8ae85d
commit 457d9395f0
5 changed files with 292 additions and 279 deletions

View File

@@ -0,0 +1,32 @@
package tasks
import (
"context"
"time"
"vctp/db"
)
// runAggregateJob wraps aggregation cron jobs with timeout, migration check, and circuit breaker semantics.
func (c *CronTask) runAggregateJob(ctx context.Context, jobName string, timeout time.Duration, fn func(context.Context) error) (err error) {
jobCtx := ctx
if timeout > 0 {
var cancel context.CancelFunc
jobCtx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()
}
tracker := NewCronTracker(c.Database)
done, skip, err := tracker.Start(jobCtx, jobName)
if err != nil {
return err
}
if skip {
return nil
}
defer func() { done(err) }()
if err := db.CheckMigrationState(jobCtx, c.Database.DB()); err != nil {
return err
}
return fn(jobCtx)
}