Measure schedule time

This commit is contained in:
Andre Medeiros 2021-07-08 22:15:28 -04:00
parent d65bab7970
commit b7aea89cfc

View file

@ -115,14 +115,16 @@ func main() {
} }
func enqueueAccounts(ctx context.Context, logger *logrus.Logger, statsd *statsd.Client, pool *pgxpool.Pool, redisConn *redis.Client, queue rmq.Queue) { func enqueueAccounts(ctx context.Context, logger *logrus.Logger, statsd *statsd.Client, pool *pgxpool.Pool, redisConn *redis.Client, queue rmq.Queue) {
start := time.Now()
now := float64(time.Now().UnixNano()/int64(time.Millisecond)) / 1000 now := float64(time.Now().UnixNano()/int64(time.Millisecond)) / 1000
// Start looking for accounts that were last checked at least 5 seconds ago // Start looking for accounts that were last checked at least 5 seconds ago
// and at most 6 seconds ago. Also look for accounts that haven't been checked // and at most 6 seconds ago. Also look for accounts that haven't been checked
// in over a minute. // in over a minute.
ts := time.Now().Unix() ts := start.Unix()
start := ts - 6 left := ts - 6
end := start + 1 right := left + 1
expired := ts - 60 expired := ts - 60
ids := []int64{} ids := []int64{}
@ -141,7 +143,7 @@ func enqueueAccounts(ctx context.Context, logger *logrus.Logger, statsd *statsd.
SET last_enqueued_at = $4 SET last_enqueued_at = $4
WHERE accounts.id IN(SELECT id FROM account) WHERE accounts.id IN(SELECT id FROM account)
RETURNING accounts.id` RETURNING accounts.id`
rows, err := tx.Query(ctx, stmt, start, end, expired, now) rows, err := tx.Query(ctx, stmt, left, right, expired, now)
if err != nil { if err != nil {
return err return err
} }
@ -163,8 +165,8 @@ func enqueueAccounts(ctx context.Context, logger *logrus.Logger, statsd *statsd.
logger.WithFields(logrus.Fields{ logger.WithFields(logrus.Fields{
"count": len(ids), "count": len(ids),
"start": start, "start": left,
"end": end, "end": right,
}).Debug("enqueueing account batch") }).Debug("enqueueing account batch")
enqueued := 0 enqueued := 0
@ -206,13 +208,14 @@ func enqueueAccounts(ctx context.Context, logger *logrus.Logger, statsd *statsd.
statsd.Histogram("apollo.queue.enqueued", float64(enqueued), []string{}, 1) statsd.Histogram("apollo.queue.enqueued", float64(enqueued), []string{}, 1)
statsd.Histogram("apollo.queue.skipped", float64(skipped), []string{}, 1) statsd.Histogram("apollo.queue.skipped", float64(skipped), []string{}, 1)
statsd.Histogram("apollo.queue.failed", float64(failed), []string{}, 1) statsd.Histogram("apollo.queue.failed", float64(failed), []string{}, 1)
statsd.Histogram("apollo.queue.runtime", float64(time.Now().Sub(start).Milliseconds()), []string{}, 1)
logger.WithFields(logrus.Fields{ logger.WithFields(logrus.Fields{
"count": enqueued, "count": enqueued,
"skipped": skipped, "skipped": skipped,
"failed": failed, "failed": failed,
"start": start, "start": left,
"end": end, "end": right,
}).Info("done enqueueing account batch") }).Info("done enqueueing account batch")
} }