@jayfong/x-server 2.24.1 → 2.24.2

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.
@@ -67,23 +67,28 @@ function defineSliceTask(options) {
67
67
  // 仅阈值
68
68
  // 满10条推送
69
69
  else if (threshold != null) {
70
- if (thresholdTimeout) {
71
- const delayTaskId = redisKey;
72
- await task.getJob(delayTaskId).then(job => job == null ? void 0 : job.remove());
70
+ const delayTaskId = redisKey;
71
+ const prevJob = await task.getJob(delayTaskId);
72
+
73
+ // 到达阈值,立即发送
74
+ if (count === threshold) {
75
+ await (prevJob == null ? void 0 : prevJob.remove());
73
76
  await task.add({
74
77
  key: key,
75
78
  redisKey: redisKey
76
- }, {
77
- jobId: delayTaskId,
78
- delay: thresholdTimeout
79
79
  });
80
80
  }
81
- if (count === threshold) {
82
- await task.add({
83
- key: key,
84
- redisKey: redisKey,
85
- count: threshold
86
- });
81
+ // 存在超时设置
82
+ else if (thresholdTimeout) {
83
+ if (!prevJob) {
84
+ await task.add({
85
+ key: key,
86
+ redisKey: redisKey
87
+ }, {
88
+ jobId: delayTaskId,
89
+ delay: thresholdTimeout
90
+ });
91
+ }
87
92
  }
88
93
  }
89
94
  }
@@ -61,23 +61,28 @@ export function defineSliceTask(options) {
61
61
  // 仅阈值
62
62
  // 满10条推送
63
63
  else if (threshold != null) {
64
- if (thresholdTimeout) {
65
- const delayTaskId = redisKey;
66
- await task.getJob(delayTaskId).then(job => job == null ? void 0 : job.remove());
64
+ const delayTaskId = redisKey;
65
+ const prevJob = await task.getJob(delayTaskId);
66
+
67
+ // 到达阈值,立即发送
68
+ if (count === threshold) {
69
+ await (prevJob == null ? void 0 : prevJob.remove());
67
70
  await task.add({
68
71
  key: key,
69
72
  redisKey: redisKey
70
- }, {
71
- jobId: delayTaskId,
72
- delay: thresholdTimeout
73
73
  });
74
74
  }
75
- if (count === threshold) {
76
- await task.add({
77
- key: key,
78
- redisKey: redisKey,
79
- count: threshold
80
- });
75
+ // 存在超时设置
76
+ else if (thresholdTimeout) {
77
+ if (!prevJob) {
78
+ await task.add({
79
+ key: key,
80
+ redisKey: redisKey
81
+ }, {
82
+ jobId: delayTaskId,
83
+ delay: thresholdTimeout
84
+ });
85
+ }
81
86
  }
82
87
  }
83
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.24.1",
3
+ "version": "2.24.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",