|
| 1 | +import { createRedisClient } from "@internal/redis"; |
1 | 2 | import { Logger } from "@trigger.dev/core/logger"; |
2 | 3 | import Redis, { type Callback, type RedisOptions, type Result } from "ioredis"; |
3 | 4 | import { nanoid } from "nanoid"; |
@@ -50,35 +51,29 @@ export class SimpleQueue<TMessageCatalog extends MessageCatalogSchema> { |
50 | 51 | logger?: Logger; |
51 | 52 | }) { |
52 | 53 | this.name = name; |
53 | | - this.redis = new Redis({ |
54 | | - ...redisOptions, |
55 | | - keyPrefix: `${redisOptions.keyPrefix ?? ""}{queue:${name}:}`, |
56 | | - retryStrategy(times) { |
57 | | - const delay = Math.min(times * 50, 1000); |
58 | | - return delay; |
| 54 | + this.logger = logger ?? new Logger("SimpleQueue", "debug"); |
| 55 | + |
| 56 | + this.redis = createRedisClient( |
| 57 | + { |
| 58 | + ...redisOptions, |
| 59 | + keyPrefix: `${redisOptions.keyPrefix ?? ""}{queue:${name}:}`, |
| 60 | + retryStrategy(times) { |
| 61 | + const delay = Math.min(times * 50, 1000); |
| 62 | + return delay; |
| 63 | + }, |
| 64 | + maxRetriesPerRequest: 20, |
59 | 65 | }, |
60 | | - maxRetriesPerRequest: 20, |
61 | | - }); |
| 66 | + { |
| 67 | + onError: (error) => { |
| 68 | + this.logger.error(`RedisWorker queue redis client error:`, { |
| 69 | + error, |
| 70 | + keyPrefix: redisOptions.keyPrefix, |
| 71 | + }); |
| 72 | + }, |
| 73 | + } |
| 74 | + ); |
62 | 75 | this.#registerCommands(); |
63 | 76 | this.schema = schema; |
64 | | - |
65 | | - this.logger = logger ?? new Logger("SimpleQueue", "debug"); |
66 | | - |
67 | | - this.redis.on("error", (error) => { |
68 | | - this.logger.error(`Redis Error for queue ${this.name}:`, { queue: this.name, error }); |
69 | | - }); |
70 | | - |
71 | | - this.redis.on("connect", () => { |
72 | | - this.logger.log(`Redis connected for queue ${this.name}`); |
73 | | - }); |
74 | | - |
75 | | - this.redis.on("reconnecting", () => { |
76 | | - this.logger.warn(`Redis reconnecting for queue ${this.name}`); |
77 | | - }); |
78 | | - |
79 | | - this.redis.on("close", () => { |
80 | | - this.logger.warn(`Redis connection closed for queue ${this.name}`); |
81 | | - }); |
82 | 77 | } |
83 | 78 |
|
84 | 79 | async enqueue({ |
|
0 commit comments