Skip to content

Commit

Permalink
Merge pull request #384 from nyaruka/metrics_task_delay
Browse files Browse the repository at this point in the history
Tweak metrics cron so that instead of sleeping there is an offset added to the next time
  • Loading branch information
rowanseymour authored Dec 16, 2024
2 parents d18442f + 644d171 commit 2d74a1d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions core/tasks/metrics/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,16 @@ type metricsCron struct {
}

func (c *metricsCron) Next(last time.Time) time.Time {
return tasks.CronNext(last, time.Minute)
// We offset 30 seconds from the top of the minute so that metrics related to queue sizes don't see the spikes that
// typically occur every minute by tasks such as expirations, timeouts etc.
return tasks.CronNext(last, time.Minute).Add(time.Second * 30)
}

func (c *metricsCron) AllInstances() bool {
return true
}

func (c *metricsCron) Run(ctx context.Context, rt *runtime.Runtime) (map[string]any, error) {
// TODO replace with offset passed to tasks.CronNext
// We wait 15 seconds since we fire at the top of the minute, the same as expirations.
// That way any metrics related to the size of our queue are a bit more accurate (all expirations can
// usually be handled in 15 seconds). Something more complicated would take into account the age of
// the items in our queues.
time.Sleep(time.Second * 15)

handlerSize, batchSize, throttledSize := getQueueSizes(rt)

// get our DB and redis stats
Expand Down

0 comments on commit 2d74a1d

Please sign in to comment.