@jayfong/x-server 1.35.3 → 1.35.4
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/lib/_cjs/core/define_task.js +13 -7
- package/lib/core/define_task.js +13 -7
- package/package.json +1 -1
|
@@ -57,23 +57,28 @@ function defineSliceTask(options) {
|
|
|
57
57
|
const redisKey = !key ? redisKeyPrefix : `${redisKeyPrefix}_${key}`;
|
|
58
58
|
const res = await _x.x.redis.multi([['llen', redisKey], ['lpush', redisKey, JSON.stringify(data)]]).exec();
|
|
59
59
|
const count = parseInt(res[0][1], 10) + 1; // 时段与阈值并存
|
|
60
|
+
// 满10条推送,若超过1分钟仍未满10条,则亦推送
|
|
60
61
|
|
|
61
62
|
if (duration != null && threshold != null) {
|
|
63
|
+
const delayTaskId = redisKey;
|
|
64
|
+
await task.getJob(delayTaskId).then(job => job == null ? void 0 : job.remove());
|
|
65
|
+
await task.add({
|
|
66
|
+
key: key,
|
|
67
|
+
redisKey: redisKey
|
|
68
|
+
}, {
|
|
69
|
+
jobId: delayTaskId,
|
|
70
|
+
delay: duration
|
|
71
|
+
});
|
|
72
|
+
|
|
62
73
|
if (count === threshold) {
|
|
63
74
|
await task.add({
|
|
64
75
|
key: key,
|
|
65
76
|
redisKey: redisKey,
|
|
66
77
|
count: threshold
|
|
67
78
|
});
|
|
68
|
-
} else if (count === 1) {
|
|
69
|
-
await task.add({
|
|
70
|
-
key: key,
|
|
71
|
-
redisKey: redisKey
|
|
72
|
-
}, {
|
|
73
|
-
delay: duration
|
|
74
|
-
});
|
|
75
79
|
}
|
|
76
80
|
} // 仅时段
|
|
81
|
+
// 1分钟内的合并推送
|
|
77
82
|
else if (duration != null) {
|
|
78
83
|
if (count === 1) {
|
|
79
84
|
await task.add({
|
|
@@ -84,6 +89,7 @@ function defineSliceTask(options) {
|
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
91
|
} // 仅阈值
|
|
92
|
+
// 满10条推送
|
|
87
93
|
else if (threshold != null) {
|
|
88
94
|
if (count === threshold) {
|
|
89
95
|
await task.add({
|
package/lib/core/define_task.js
CHANGED
|
@@ -44,23 +44,28 @@ export function defineSliceTask(options) {
|
|
|
44
44
|
const redisKey = !key ? redisKeyPrefix : `${redisKeyPrefix}_${key}`;
|
|
45
45
|
const res = await x.redis.multi([['llen', redisKey], ['lpush', redisKey, JSON.stringify(data)]]).exec();
|
|
46
46
|
const count = parseInt(res[0][1], 10) + 1; // 时段与阈值并存
|
|
47
|
+
// 满10条推送,若超过1分钟仍未满10条,则亦推送
|
|
47
48
|
|
|
48
49
|
if (duration != null && threshold != null) {
|
|
50
|
+
const delayTaskId = redisKey;
|
|
51
|
+
await task.getJob(delayTaskId).then(job => job == null ? void 0 : job.remove());
|
|
52
|
+
await task.add({
|
|
53
|
+
key: key,
|
|
54
|
+
redisKey: redisKey
|
|
55
|
+
}, {
|
|
56
|
+
jobId: delayTaskId,
|
|
57
|
+
delay: duration
|
|
58
|
+
});
|
|
59
|
+
|
|
49
60
|
if (count === threshold) {
|
|
50
61
|
await task.add({
|
|
51
62
|
key: key,
|
|
52
63
|
redisKey: redisKey,
|
|
53
64
|
count: threshold
|
|
54
65
|
});
|
|
55
|
-
} else if (count === 1) {
|
|
56
|
-
await task.add({
|
|
57
|
-
key: key,
|
|
58
|
-
redisKey: redisKey
|
|
59
|
-
}, {
|
|
60
|
-
delay: duration
|
|
61
|
-
});
|
|
62
66
|
}
|
|
63
67
|
} // 仅时段
|
|
68
|
+
// 1分钟内的合并推送
|
|
64
69
|
else if (duration != null) {
|
|
65
70
|
if (count === 1) {
|
|
66
71
|
await task.add({
|
|
@@ -71,6 +76,7 @@ export function defineSliceTask(options) {
|
|
|
71
76
|
});
|
|
72
77
|
}
|
|
73
78
|
} // 仅阈值
|
|
79
|
+
// 满10条推送
|
|
74
80
|
else if (threshold != null) {
|
|
75
81
|
if (count === threshold) {
|
|
76
82
|
await task.add({
|