mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 11:47:42 +00:00
Measure schedule time
This commit is contained in:
parent
d65bab7970
commit
b7aea89cfc
1 changed files with 11 additions and 8 deletions
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue