mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 11:47:42 +00:00
enqueue by batches
This commit is contained in:
parent
45576b4d16
commit
0f70725be5
1 changed files with 8 additions and 7 deletions
|
@ -107,10 +107,8 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func enqueueAccounts(ctx context.Context, logger *logrus.Logger, pool *pgxpool.Pool, redisConn *redis.Client, queue rmq.Queue) {
|
func enqueueAccounts(ctx context.Context, logger *logrus.Logger, pool *pgxpool.Pool, redisConn *redis.Client, queue rmq.Queue) {
|
||||||
now := float64(time.Now().UnixNano()/int64(time.Millisecond)) / 1000
|
start := time.Now().Unix()
|
||||||
|
end := start + 1
|
||||||
start := now
|
|
||||||
end := now + 1
|
|
||||||
|
|
||||||
ids := []int64{}
|
ids := []int64{}
|
||||||
|
|
||||||
|
@ -119,10 +117,13 @@ func enqueueAccounts(ctx context.Context, logger *logrus.Logger, pool *pgxpool.P
|
||||||
WITH account AS (
|
WITH account AS (
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM accounts
|
FROM accounts
|
||||||
WHERE (last_checked_at + 5) BETWEEN $1 AND $2
|
WHERE
|
||||||
|
(
|
||||||
|
(last_checked_at + 5) >= $1 AND
|
||||||
|
(last_checked_at + 5) < $2
|
||||||
|
)
|
||||||
OR last_checked_at + 60 < $1
|
OR last_checked_at + 60 < $1
|
||||||
ORDER BY last_checked_at
|
ORDER BY last_checked_at
|
||||||
FOR UPDATE SKIP LOCKED
|
|
||||||
)
|
)
|
||||||
UPDATE accounts
|
UPDATE accounts
|
||||||
SET last_enqueued_at = $1
|
SET last_enqueued_at = $1
|
||||||
|
|
Loading…
Reference in a new issue