Skip to content

Commit 2976a40

Browse files
authored
feat: add support for bullmq v6 and postgresql (#138)
1 parent 2137de1 commit 2976a40

23 files changed

Lines changed: 3184 additions & 1398 deletions

lib/cmd.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,41 @@ export const run = (name: string, version: string) => {
7979
"file with queues to monitor"
8080
).conflicts("queues")
8181
)
82+
// PostgreSQL backend options (BullMQ v6+)
83+
.addOption(
84+
new Option(
85+
"--pg-host <host>",
86+
"PostgreSQL host (enables PG backend instead of Redis)"
87+
)
88+
.env("PG_HOST")
89+
.conflicts(["uri", "nodes", "sentinels"])
90+
)
91+
.option(
92+
"--pg-port [port]",
93+
"PostgreSQL port [5432]",
94+
process.env.PG_PORT || "5432"
95+
)
96+
.option(
97+
"--pg-database [database]",
98+
"PostgreSQL database name",
99+
process.env.PG_DATABASE
100+
)
101+
.option(
102+
"--pg-user [user]",
103+
"PostgreSQL user",
104+
process.env.PG_USER
105+
)
106+
.option(
107+
"--pg-password [password]",
108+
"PostgreSQL password",
109+
process.env.PG_PASSWORD
110+
)
111+
.option(
112+
"--pg-schema [schema]",
113+
"PostgreSQL schema for BullMQ tables [bullmq]",
114+
process.env.PG_SCHEMA
115+
)
116+
.option("--pg-ssl", "enable SSL for PostgreSQL connection")
82117
.parse(process.argv);
83118

84119
const options = program.opts();
@@ -105,6 +140,22 @@ export const run = (name: string, version: string) => {
105140
process.exit(1);
106141
}
107142

143+
// Validate PostgreSQL options when PG backend is selected
144+
if (options.pgHost) {
145+
if (!options.pgDatabase) {
146+
console.error(
147+
red("ERROR: --pg-database is required when using PostgreSQL backend")
148+
);
149+
process.exit(1);
150+
}
151+
if (!options.pgUser) {
152+
console.error(
153+
red("ERROR: --pg-user is required when using PostgreSQL backend")
154+
);
155+
process.exit(1);
156+
}
157+
}
158+
108159
const queueNames = options.queuesFile
109160
? parseQueuesFile(options.queuesFile)
110161
: options.queues
@@ -148,10 +199,23 @@ export const run = (name: string, version: string) => {
148199
});
149200
}
150201

202+
const parsedPgPort = Number.parseInt(options.pgPort, 10);
203+
151204
Socket(options.name, options.backend, options.token, connection, {
152205
team: options.team,
153206
nodes: options.nodes ? options.nodes.split(",") : undefined,
154207
queueNames,
208+
pgOpts: options.pgHost
209+
? {
210+
host: options.pgHost,
211+
port: Number.isNaN(parsedPgPort) ? 5432 : parsedPgPort,
212+
database: options.pgDatabase,
213+
user: options.pgUser,
214+
password: options.pgPassword,
215+
schema: options.pgSchema,
216+
ssl: options.pgSsl || false,
217+
}
218+
: undefined,
155219
});
156220
});
157221

lib/interfaces/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface Integration {
66
responders: Responders;
77
createQueue: (
88
foundQueue: FoundQueue,
9-
redisOpts: RedisOptions,
9+
redisOpts: RedisOptions | undefined,
1010
nodes?: string[]
1111
) => any;
1212
}

0 commit comments

Comments
 (0)