forked from pavel-voronin/bullmq-dashboard-runnable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·65 lines (52 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const { createBullBoard } = require("@bull-board/api");
const { BullMQAdapter } = require("@bull-board/api/bullMQAdapter");
const { ExpressAdapter } = require("@bull-board/express");
const { Queue } = require("bullmq");
const express = require("express");
const { program } = require("commander");
const split = (str) => str.split(",");
function myParseInt(value) {
const parsedValue = parseInt(value, 10);
if (isNaN(parsedValue)) {
throw new program.InvalidArgumentError("Not a number.");
}
return parsedValue;
}
program
.showHelpAfterError()
.option("-P, --port <port>", "Port to run UI", myParseInt, 3000)
.option("--redis-port <port>", "Redis port", myParseInt, 6379)
.option("--redis-host <host>", "Redis host", "localhost")
.option("--redis-password <password>", "Redis password", undefined)
.option("--prefix <prefix>", "BullMQ prefix", undefined)
.option("--use-tls", "Use TLS when connecting", false)
.argument("<names>", "comma separated queue names", split)
.action((names, opts) => {
const redisOptions = {
port: opts.redisPort,
host: opts.redisHost,
password: opts.redisPassword,
...(opts.useTls && {
tls: {},
}),
};
const run = async () => {
const queues = names.map(
(name) =>
new BullMQAdapter(
new Queue(name, { ...(opts.prefix ? { prefix: opts.prefix } : {}), connection: redisOptions })
)
);
const app = express();
const serverAdapter = new ExpressAdapter();
serverAdapter.setBasePath("/");
createBullBoard({ queues, serverAdapter });
app.use("/", serverAdapter.getRouter());
app.listen(opts.port, () => {
console.log(`For the UI, open http://localhost:${opts.port}/`);
});
};
run().catch((e) => console.error(e));
});
program.parse();