Skip to content

Commit 4dee10f

Browse files
committed
feat: better logs when getting connection
1 parent 67235bf commit 4dee10f

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

lib/socket.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RedisOptions } from "ioredis";
22
import { pick } from "lodash";
33
import { getCache, updateQueuesCache, queueKey } from "./queues-cache";
44
import { WebSocketClient } from "./ws-autoreconnect";
5-
import { execRedisCommand, getRedisInfo, ping } from "./queue-factory";
5+
import { FoundQueue, execRedisCommand, getRedisInfo, ping } from "./queue-factory";
66
import { getQueueType, redisOptsFromUrl } from "./utils";
77
import { Integration } from "./interfaces/integration";
88

@@ -52,8 +52,8 @@ export const Socket = (
5252
ws.onopen = function open() {
5353
console.log(
5454
chalk.yellow("WebSocket:") +
55-
chalk.blueBright(" opened connection to ") +
56-
chalk.gray("Taskforce.sh")
55+
chalk.blueBright(" opened connection to ") +
56+
chalk.gray("Taskforce.sh")
5757
);
5858
};
5959

@@ -78,7 +78,7 @@ export const Socket = (
7878
if (input === "authorized") {
7979
console.log(
8080
chalk.yellow("WebSocket: ") +
81-
chalk.green("Succesfully authorized to taskforce.sh service")
81+
chalk.green("Succesfully authorized to taskforce.sh service")
8282
);
8383

8484
//
@@ -91,8 +91,7 @@ export const Socket = (
9191
console.log(
9292
`${chalk.yellow("WebSocket: ")} ${chalk.green(
9393
"sending connection: "
94-
)} ${chalk.blueBright(name)} ${
95-
team ? chalk.green(" for team ") + chalk.blueBright(team) : ""
94+
)} ${chalk.blueBright(name)} ${team ? chalk.green(" for team ") + chalk.blueBright(team) : ""
9695
}`
9796
);
9897
ws.send(
@@ -111,7 +110,7 @@ export const Socket = (
111110
if (!msg.data) {
112111
console.error(
113112
chalk.red("WebSocket:") +
114-
chalk.blueBright(" missing message data "),
113+
chalk.blueBright(" missing message data "),
115114
msg
116115
);
117116
return;
@@ -131,7 +130,7 @@ export const Socket = (
131130
}
132131
const { queue, responders } =
133132
cache[
134-
queueKey({ name: queueName, prefix: queuePrefix || "bull" })
133+
queueKey({ name: queueName, prefix: queuePrefix || "bull" })
135134
];
136135

137136
if (!queue) {
@@ -173,11 +172,12 @@ export const Socket = (
173172
console.log(
174173
`${chalk.yellow("WebSocket: ")} ${chalk.green(
175174
"sending connection:"
176-
)} ${chalk.blueBright(name)} ${
177-
team ? chalk.green(" for team ") + chalk.blueBright(team) : ""
175+
)} ${chalk.blueBright(name)} ${team ? chalk.green(" for team ") + chalk.blueBright(team) : ""
178176
}`
179177
);
180178

179+
logSendingQueues(queues)
180+
181181
respond(msg.id, {
182182
queues,
183183
connection: name,
@@ -190,18 +190,7 @@ export const Socket = (
190190
{
191191
const queues = await updateQueuesCache(redisOpts, opts);
192192

193-
for (const queue of queues) {
194-
const { name, prefix, type } = queue;
195-
console.log(
196-
`${chalk.yellow("WebSocket:")} ${chalk.blueBright(
197-
"Sending queue:"
198-
)} ${chalk.green(name)} ${chalk.blueBright(
199-
"type:"
200-
)} ${chalk.green(type)} ${chalk.blueBright(
201-
"prefix:"
202-
)} ${chalk.green(prefix)}`
203-
);
204-
}
193+
logSendingQueues(queues);
205194

206195
respond(msg.id, queues);
207196
}
@@ -222,6 +211,21 @@ export const Socket = (
222211
}
223212
}
224213

214+
function logSendingQueues(queues: FoundQueue[]) {
215+
for (const queue of queues) {
216+
const { name, prefix, type } = queue;
217+
console.log(
218+
`${chalk.yellow("WebSocket:")} ${chalk.blueBright(
219+
"Sending queue:"
220+
)} ${chalk.green(name)} ${chalk.blueBright(
221+
"type:"
222+
)} ${chalk.green(type)} ${chalk.blueBright(
223+
"prefix:"
224+
)} ${chalk.green(prefix)}`
225+
);
226+
}
227+
}
228+
225229
function respond(id: string, data: any = {}) {
226230
const response = JSON.stringify({
227231
id,

0 commit comments

Comments
 (0)