joye-backend-utility 7.3.5 → 7.3.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/redisClient.d.ts +4 -2
- package/dist/redisClient.js +38 -15
- package/dist/schema/user_analytic.js +7 -0
- package/package.json +1 -1
package/dist/redisClient.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { createClient } from 'redis';
|
|
1
|
+
import { createClient, createCluster } from 'redis';
|
|
2
|
+
/** Connected standalone client or cluster client (commands used by callers are supported on both). */
|
|
3
|
+
export declare type RedisConnection = Awaited<ReturnType<ReturnType<typeof createClient>['connect']>> | ReturnType<typeof createCluster>;
|
|
2
4
|
declare class RedisClient {
|
|
3
5
|
private static instance;
|
|
4
|
-
static getInstance(): Promise<
|
|
6
|
+
static getInstance(): Promise<RedisConnection>;
|
|
5
7
|
}
|
|
6
8
|
export { RedisClient };
|
package/dist/redisClient.js
CHANGED
|
@@ -8,24 +8,47 @@ class RedisClient {
|
|
|
8
8
|
const cachePort = process.env.REDIS_CACHE_PORT;
|
|
9
9
|
const cacheHostName = process.env.REDIS_CACHE_HOST;
|
|
10
10
|
const cachePassword = process.env.REDIS_CACHE_PASSWORD;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const url = `rediss://${cacheHostName}:${cachePort}`;
|
|
12
|
+
const useCluster = process.env.REDIS_CACHE_CLUSTER === 'true';
|
|
13
|
+
const clientOptions = {
|
|
14
|
+
url,
|
|
14
15
|
password: cachePassword,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
};
|
|
17
|
+
if (useCluster) {
|
|
18
|
+
const cluster = (0, redis_1.createCluster)({
|
|
19
|
+
rootNodes: [clientOptions],
|
|
20
|
+
defaults: {
|
|
21
|
+
password: cachePassword,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
.on('error', err => {
|
|
25
|
+
console.log('Redis Client Error', err);
|
|
26
|
+
})
|
|
27
|
+
.on('connect', () => {
|
|
28
|
+
console.log('Connected to Redis');
|
|
29
|
+
})
|
|
30
|
+
.on('end', () => {
|
|
31
|
+
console.log('Connection to Redis end');
|
|
32
|
+
});
|
|
33
|
+
await cluster.connect();
|
|
34
|
+
RedisClient.instance = cluster;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const client = (0, redis_1.createClient)(clientOptions)
|
|
38
|
+
.on('error', err => {
|
|
39
|
+
console.log('Redis Client Error', err);
|
|
40
|
+
})
|
|
41
|
+
.on('connect', () => {
|
|
42
|
+
console.log('Connected to Redis');
|
|
43
|
+
})
|
|
44
|
+
.on('end', () => {
|
|
45
|
+
console.log('Connection to Redis end');
|
|
46
|
+
});
|
|
47
|
+
RedisClient.instance = await client.connect();
|
|
48
|
+
}
|
|
26
49
|
}
|
|
27
50
|
if (!RedisClient.instance.isOpen) {
|
|
28
|
-
|
|
51
|
+
await RedisClient.instance.connect();
|
|
29
52
|
}
|
|
30
53
|
return RedisClient.instance;
|
|
31
54
|
}
|
|
@@ -8,6 +8,12 @@ const UserAnalytic = new mongoose_1.Schema({
|
|
|
8
8
|
required: true,
|
|
9
9
|
index: true,
|
|
10
10
|
},
|
|
11
|
+
/** Denormalized from `User.bucket` for sharded schedulers (e.g. daily-suggestion queue cron). */
|
|
12
|
+
bucket: {
|
|
13
|
+
type: Number,
|
|
14
|
+
required: false,
|
|
15
|
+
index: true,
|
|
16
|
+
},
|
|
11
17
|
date: {
|
|
12
18
|
type: String,
|
|
13
19
|
required: true,
|
|
@@ -133,4 +139,5 @@ const UserAnalytic = new mongoose_1.Schema({
|
|
|
133
139
|
});
|
|
134
140
|
UserAnalytic.index({ employeeId: 1, weekNumber: -1, year: -1, date: -1 });
|
|
135
141
|
UserAnalytic.index({ employeeId: 1, month: -1, year: -1, date: -1 });
|
|
142
|
+
UserAnalytic.index({ year: 1, weekNumber: 1, bucket: 1 });
|
|
136
143
|
exports.UserAnalyticSchema = UserAnalytic;
|