-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.ts
95 lines (89 loc) · 2.05 KB
/
client.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//import { createClient } from "@redis/client";
import { randomUUID } from "crypto";
import { Queue } from "bullmq";
import * as dotenv from "dotenv"; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
import { imageProcess, videoProcess } from "./types";
dotenv.config();
// const client = createClient({
// url: process.env.REDIS_URL,
// });
if (!process.env.PORT) throw new Error("redis env not defiend");
// video-prossing
// image-prossing
const queue = new Queue(imageProcess, {
connection: {
host: process.env.HOST,
port: parseInt(process.env.PORT),
password: process.env.PASSWORD,
name: process.env.NAME,
},
});
const every = 1000 * 60 * 15;
const array: {
data: { qux: number; id: string; width: number; height: number };
name: string;
opts: object;
}[] = [];
for (let i = 0; i < 10; i++) {
array.push({
data: { qux: i, id: "id", width: 200, height: 200 },
name: "hls",
opts: {
removeOnComplete: true,
removeOnFail: true,
repeat: {
every: every,
limit: 5,
},
},
});
}
queue
.addBulk(array)
.then(() => {
return queue.count();
})
.then((data) => {
console.log(data);
queue.disconnect();
});
queue.on("error", (err) => {
console.log(err);
});
// queue
// .add(
// "hls",
// { qux: "jdsbjhbsdjbs sjhdbjhbsdjbjh", id: "id" },
// {
// removeOnComplete: true,
// removeOnFail: true,
// repeat: {
// every: every,
// limit: 5,
// },
// delay: 1000,
// }
// )
// .then(() => queue.disconnect());
// queue.on("error", (err) => {
// console.log(err);
// });
// client.on("error", (err) => console.log("Redis Client Error", err));
// client
// .connect()
// .then(async () => {
// await client.publish(
// "video-prossing",
// JSON.stringify({
// id: randomUUID(),
// key: randomUUID(),
// url: randomUUID(),
// })
// );
// })
// .finally(() => {
// client.disconnect();
// })
// .catch((e) => {
// console.log(e);
// });