@antelopejs/interface-redis-scheduler 0.0.8 → 0.0.10
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/README.md +22 -20
- package/dist/index.js +24 -23
- package/dist/index.js.map +1 -1
- package/dist/tests/index.test.js +189 -124
- package/dist/tests/index.test.js.map +1 -1
- package/docs/1.introduction.md +137 -68
- package/docs/assets/task-delivery.svg +18 -0
- package/docs/tsconfig.json +7 -0
- package/package.json +16 -4
- package/skills/redis-scheduler-interface/SKILL.md +49 -29
- package/skills/redis-scheduler-interface/cases.json +57 -0
package/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@antelopejs/interface-redis-scheduler`
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
|
-
<a href="https://www.npmjs.com/package/@antelopejs/interface-redis-scheduler"><img alt="npm" src="https://img.shields.io/npm/v/@antelopejs/interface-redis-scheduler?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
5
|
-
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@antelopejs/interface-redis-scheduler?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
6
|
-
<a href="https://discord.gg/
|
|
7
|
-
<a href="https://interfaces.antelopejs.com/docs/redis-scheduler"><img alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@antelopejs/interface-redis-scheduler"><img data-illustration alt="npm" src="https://img.shields.io/npm/v/@antelopejs/interface-redis-scheduler?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
5
|
+
<a href="./LICENSE"><img data-illustration alt="License" src="https://img.shields.io/npm/l/@antelopejs/interface-redis-scheduler?style=for-the-badge&labelColor=000000&color=000000"></a>
|
|
6
|
+
<a href="https://discord.gg/g4pFt6eXqu"><img data-illustration alt="Discord" src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"></a>
|
|
7
|
+
<a href="https://interfaces.antelopejs.com/docs/redis-scheduler"><img data-illustration alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
|
|
8
8
|
</div>
|
|
9
9
|
|
|
10
|
-
Task scheduling on Redis for AntelopeJS
|
|
10
|
+
Task scheduling on Redis for AntelopeJS. You schedule a task for a given time, and a listener in your application runs it when it is due, with up to three retries on failure.
|
|
11
11
|
|
|
12
12
|
## What it offers
|
|
13
13
|
|
|
14
14
|
- `setHandler` registers the function that runs one kind of task.
|
|
15
|
-
- `addTask` schedules a task for a Unix timestamp in milliseconds
|
|
16
|
-
- `enableListener` starts task processing
|
|
17
|
-
- Tasks live in a Redis sorted set, so they survive restarts and every instance of the application sees the same queue.
|
|
15
|
+
- `addTask` schedules a task for a Unix timestamp in milliseconds. `removeTask` removes the queued entry before it runs.
|
|
16
|
+
- `enableListener` starts task processing. `disableListener` closes only the notification subscriber, not the pending timer.
|
|
17
|
+
- Tasks live in a Redis sorted set, so they survive application restarts and every instance of the application sees the same queue. Each due task goes to one listener.
|
|
18
18
|
|
|
19
19
|
## Implementations
|
|
20
20
|
|
|
21
|
-
| Module | Notes
|
|
22
|
-
| ---------------------------------------------------------- |
|
|
23
|
-
| [`@antelopejs/redis`](https://github.com/AntelopeJS/redis) | Also implements `@antelopejs/interface-redis
|
|
21
|
+
| Module | Notes |
|
|
22
|
+
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| [`@antelopejs/redis`](https://github.com/AntelopeJS/redis) | Also implements `@antelopejs/interface-redis`, which supplies the Redis client the scheduler uses |
|
|
24
24
|
|
|
25
25
|
## Install
|
|
26
26
|
|
|
@@ -68,9 +68,9 @@ export async function stop() {
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
Register a handler before you schedule tasks for it
|
|
71
|
+
Register a handler before you schedule tasks for it. `addTask` rejects for a handler name that this process has not registered.
|
|
72
72
|
|
|
73
|
-
`disableListener()` is not a full shutdown or pause
|
|
73
|
+
`disableListener()` is not a full shutdown or pause. A pending timer and running handlers can continue to process tasks. Read the [lifecycle and delivery limits](./docs/1.introduction.md#disablelistener) before you use it for shutdown.
|
|
74
74
|
|
|
75
75
|
## Documentation
|
|
76
76
|
|
|
@@ -78,14 +78,16 @@ Register a handler before you schedule tasks for it: `addTask` throws for an unk
|
|
|
78
78
|
|
|
79
79
|
## Compatibility
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
The module declares these peer dependencies:
|
|
82
82
|
|
|
83
|
-
<!-- docs-compat:
|
|
83
|
+
<!-- antelopejs-docs-compat:start -->
|
|
84
84
|
|
|
85
|
-
| Package |
|
|
86
|
-
| ----------------------------- | ---------------- |
|
|
87
|
-
| `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` |
|
|
88
|
-
| `@antelopejs/interface-redis` | `>=0.0.9 <1.0.0` |
|
|
85
|
+
| Package | Supported | Tested with |
|
|
86
|
+
| ----------------------------- | ---------------- | ----------- |
|
|
87
|
+
| `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` | `0.2.4` |
|
|
88
|
+
| `@antelopejs/interface-redis` | `>=0.0.9 <1.0.0` | `0.0.9` |
|
|
89
|
+
|
|
90
|
+
<!-- antelopejs-docs-compat:end -->
|
|
89
91
|
|
|
90
92
|
## Contributing
|
|
91
93
|
|
package/dist/index.js
CHANGED
|
@@ -57,9 +57,6 @@ function setHandler(handlerName, handler) {
|
|
|
57
57
|
}
|
|
58
58
|
/** Redis subscriber client for receiving task updates */
|
|
59
59
|
let subscriber;
|
|
60
|
-
const SubscriberMessageHandlers = {
|
|
61
|
-
[SchedulerUpdateMessage]: () => void updateTimer(),
|
|
62
|
-
};
|
|
63
60
|
function createTaskMember(handlerName, taskInfo) {
|
|
64
61
|
return `${handlerName}:${taskInfo}`;
|
|
65
62
|
}
|
|
@@ -90,11 +87,9 @@ async function enableListener() {
|
|
|
90
87
|
if (channel !== SchedulerChannel) {
|
|
91
88
|
return;
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return;
|
|
90
|
+
if (message === SchedulerUpdateMessage) {
|
|
91
|
+
void updateTimer();
|
|
96
92
|
}
|
|
97
|
-
handler();
|
|
98
93
|
});
|
|
99
94
|
void updateTimer();
|
|
100
95
|
}
|
|
@@ -217,6 +212,15 @@ async function updateTimer() {
|
|
|
217
212
|
}
|
|
218
213
|
}
|
|
219
214
|
}
|
|
215
|
+
const TakeDueTasksScript = `
|
|
216
|
+
local due = redis.call("ZRANGEBYSCORE", KEYS[1], 0, ARGV[1])
|
|
217
|
+
redis.call("ZREMRANGEBYSCORE", KEYS[1], 0, ARGV[1])
|
|
218
|
+
return due
|
|
219
|
+
`;
|
|
220
|
+
async function takeDueTasks(client) {
|
|
221
|
+
const tasks = await client.eval(TakeDueTasksScript, 1, RedisKey, Date.now());
|
|
222
|
+
return Array.isArray(tasks) ? tasks.map(String) : [];
|
|
223
|
+
}
|
|
220
224
|
/**
|
|
221
225
|
* Executes all due tasks
|
|
222
226
|
* This is called internally by the timer when tasks are due for execution
|
|
@@ -225,23 +229,20 @@ async function updateTimer() {
|
|
|
225
229
|
async function runTasks() {
|
|
226
230
|
locked = true;
|
|
227
231
|
const client = await (0, interface_redis_1.GetClient)();
|
|
228
|
-
const tasks = await client
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (m && handlers.has(m[2])) {
|
|
235
|
-
await handlers.get(m[2])?.(m[3]);
|
|
236
|
-
}
|
|
232
|
+
const tasks = await takeDueTasks(client);
|
|
233
|
+
for (const task of tasks) {
|
|
234
|
+
const m = task.match(RetryPattern);
|
|
235
|
+
try {
|
|
236
|
+
if (m && handlers.has(m[2])) {
|
|
237
|
+
await handlers.get(m[2])?.(m[3]);
|
|
237
238
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
logging_1.Logging.Error(err);
|
|
242
|
+
if (m) {
|
|
243
|
+
const retryCount = m[1] ? parseInt(m[1], 10) : 0;
|
|
244
|
+
if (retryCount < MaxRetries) {
|
|
245
|
+
await client.zadd(RedisKey, Date.now() + RetryDelayMs, `RETRY-${retryCount + 1}:${m[2]}:${m[3]}`);
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAyDA,gCAEC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAyDA,gCAEC;AA4BD,wCAcC;AAkBD,0CAEC;AA8BD,0BAcC;AA0BD,gCAMC;AAWD,kCAyBC;AAkBD,4BA0BC;AApRD,iEAAwD;AACxD,gEAA6D;AAC7D,+DAA8D;AAQ9D,8DAA8D;AAC9D,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AACzC,MAAM,sBAAsB,GAAG,QAAQ,CAAC;AACxC,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,eAAe,GAAG,QAAQ,CAAC;AACjC,MAAM,YAAY,GAAG,iCAAiC,CAAC;AAEvD,8CAA8C;AAC9C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;AAChD,wDAAwD;AACxD,MAAM,KAAK,GAAG,IAAI,iCAAgB,EAE/B,CAAC;AACJ,KAAK,CAAC,UAAU,CAAC,CAAC,WAAmB,EAAE,OAAoB,EAAE,EAAE;IAC7D,IAAI,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACpC,MAAM,IAA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AC,MAAM,CAAC,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACnC,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5B,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,iBAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,IAAI,CAAC,EAAE,CAAC;gBACN,MAAM,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjD,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;oBAC5B,MAAM,MAAM,CAAC,IAAI,CACf,QAAQ,EACR,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,EACzB,SAAS,UAAU,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAC1C,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,GAAG,KAAK,CAAC;IACf,MAAM,WAAW,EAAE,CAAC;AACtB,CAAC"}
|
package/dist/tests/index.test.js
CHANGED
|
@@ -2,150 +2,215 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const chai_1 = require("chai");
|
|
4
4
|
const interface_redis_1 = require("@antelopejs/interface-redis");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("../index");
|
|
6
6
|
const RedisKey = "SchedulerUtil.Tasks";
|
|
7
7
|
async function cleanupRedis() {
|
|
8
8
|
const client = await (0, interface_redis_1.GetClient)();
|
|
9
9
|
await client.del(RedisKey);
|
|
10
10
|
}
|
|
11
11
|
describe("Redis Scheduler - setHandler", () => {
|
|
12
|
-
it("should register a handler", async () =>
|
|
13
|
-
|
|
12
|
+
it("should register a handler", async () => {
|
|
13
|
+
let called = false;
|
|
14
|
+
(0, index_1.setHandler)("test-register", () => {
|
|
15
|
+
called = true;
|
|
16
|
+
});
|
|
17
|
+
(0, chai_1.expect)(called).to.equal(false);
|
|
18
|
+
});
|
|
19
|
+
it("should reject handler names containing :", async () => {
|
|
20
|
+
(0, chai_1.expect)(() => (0, index_1.setHandler)("invalid:name", () => { })).to.throw("may not contain");
|
|
21
|
+
});
|
|
14
22
|
});
|
|
15
23
|
describe("Redis Scheduler - addTask", () => {
|
|
16
|
-
it("should add a task to the sorted set", async () =>
|
|
17
|
-
|
|
24
|
+
it("should add a task to the sorted set", async () => {
|
|
25
|
+
await cleanupRedis();
|
|
26
|
+
(0, index_1.setHandler)("test-add", () => { });
|
|
27
|
+
const dueTime = Date.now() + 60000;
|
|
28
|
+
await (0, index_1.addTask)("test-add", dueTime, "task-data");
|
|
29
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
30
|
+
const members = await client.zrange(RedisKey, 0, -1);
|
|
31
|
+
(0, chai_1.expect)(members).to.include("test-add:task-data");
|
|
32
|
+
await cleanupRedis();
|
|
33
|
+
});
|
|
34
|
+
it("should throw for unknown handler", async () => {
|
|
35
|
+
(0, chai_1.expect)(await rejectionMessage((0, index_1.addTask)("nonexistent-handler", Date.now(), "data"))).to.include("Unknown SchedulerUtil handler");
|
|
36
|
+
});
|
|
18
37
|
});
|
|
19
38
|
describe("Redis Scheduler - removeTask", () => {
|
|
20
|
-
it("should remove a task from the sorted set", async () =>
|
|
21
|
-
|
|
39
|
+
it("should remove a task from the sorted set", async () => {
|
|
40
|
+
await cleanupRedis();
|
|
41
|
+
(0, index_1.setHandler)("test-remove", () => { });
|
|
42
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
43
|
+
await client.zadd(RedisKey, Date.now() + 60000, "test-remove:remove-data");
|
|
44
|
+
await (0, index_1.removeTask)("test-remove", "remove-data");
|
|
45
|
+
const members = await client.zrange(RedisKey, 0, -1);
|
|
46
|
+
(0, chai_1.expect)(members).to.not.include("test-remove:remove-data");
|
|
47
|
+
await cleanupRedis();
|
|
48
|
+
});
|
|
49
|
+
it("should throw for unknown handler", async () => {
|
|
50
|
+
(0, chai_1.expect)(await rejectionMessage((0, index_1.removeTask)("nonexistent-handler", "data"))).to.include("Unknown SchedulerUtil handler");
|
|
51
|
+
});
|
|
22
52
|
});
|
|
23
53
|
describe("Redis Scheduler - enableListener / disableListener", () => {
|
|
24
|
-
it("should enable and disable the listener", async () =>
|
|
25
|
-
|
|
54
|
+
it("should enable and disable the listener", async () => {
|
|
55
|
+
await cleanupRedis();
|
|
56
|
+
const executed = new Promise((resolve) => {
|
|
57
|
+
(0, index_1.setHandler)("test-listener", resolve);
|
|
58
|
+
});
|
|
59
|
+
await (0, index_1.enableListener)();
|
|
60
|
+
try {
|
|
61
|
+
await (0, index_1.addTask)("test-listener", Date.now() - 1000, "notified");
|
|
62
|
+
(0, chai_1.expect)(await executed).to.equal("notified");
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await (0, index_1.disableListener)();
|
|
66
|
+
}
|
|
67
|
+
await cleanupRedis();
|
|
68
|
+
});
|
|
69
|
+
it("should use lazyConnect when duplicating client", async () => {
|
|
70
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
71
|
+
const originalDuplicate = client.duplicate.bind(client);
|
|
72
|
+
let duplicateOptions;
|
|
73
|
+
client.duplicate = (override) => {
|
|
74
|
+
duplicateOptions = override;
|
|
75
|
+
return originalDuplicate(override);
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
await (0, index_1.enableListener)();
|
|
79
|
+
(0, chai_1.expect)(duplicateOptions).to.deep.include({ lazyConnect: true });
|
|
80
|
+
await (0, index_1.disableListener)();
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
client.duplicate = originalDuplicate;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
26
86
|
});
|
|
27
87
|
describe("Redis Scheduler - runTasks", () => {
|
|
28
|
-
it("should execute due tasks", async () =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
88
|
+
it("should execute due tasks", async () => {
|
|
89
|
+
await cleanupRedis();
|
|
90
|
+
const results = [];
|
|
91
|
+
(0, index_1.setHandler)("test-run", (taskInfo) => {
|
|
92
|
+
results.push(taskInfo);
|
|
93
|
+
});
|
|
94
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
95
|
+
await client.zadd(RedisKey, Date.now() - 1000, "test-run:payload1");
|
|
96
|
+
await client.zadd(RedisKey, Date.now() - 500, "test-run:payload2");
|
|
97
|
+
await (0, index_1.runTasks)();
|
|
98
|
+
(0, chai_1.expect)(results).to.include("payload1");
|
|
99
|
+
(0, chai_1.expect)(results).to.include("payload2");
|
|
100
|
+
const remaining = await client.zrange(RedisKey, 0, -1);
|
|
101
|
+
(0, chai_1.expect)(remaining).to.have.length(0);
|
|
102
|
+
await cleanupRedis();
|
|
38
103
|
});
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
(0,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
await
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
(0, chai_1.expect)(
|
|
104
|
+
it("should not execute future tasks", async () => {
|
|
105
|
+
await cleanupRedis();
|
|
106
|
+
const results = [];
|
|
107
|
+
(0, index_1.setHandler)("test-future", (taskInfo) => {
|
|
108
|
+
results.push(taskInfo);
|
|
109
|
+
});
|
|
110
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
111
|
+
await client.zadd(RedisKey, Date.now() + 60000, "test-future:future-data");
|
|
112
|
+
await (0, index_1.runTasks)();
|
|
113
|
+
(0, chai_1.expect)(results).to.have.length(0);
|
|
114
|
+
const remaining = await client.zrange(RedisKey, 0, -1);
|
|
115
|
+
(0, chai_1.expect)(remaining).to.have.length(1);
|
|
116
|
+
await cleanupRedis();
|
|
117
|
+
});
|
|
118
|
+
it("should keep a task rescheduled while due tasks are collected", async () => {
|
|
119
|
+
await cleanupRedis();
|
|
120
|
+
const results = [];
|
|
121
|
+
(0, index_1.setHandler)("test-reschedule", (taskInfo) => {
|
|
122
|
+
results.push(taskInfo);
|
|
123
|
+
});
|
|
124
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
125
|
+
const later = Date.now() + 60000;
|
|
126
|
+
await client.zadd(RedisKey, Date.now() - 1000, "test-reschedule:renewal");
|
|
127
|
+
await Promise.all([
|
|
128
|
+
(0, index_1.runTasks)(),
|
|
129
|
+
(0, index_1.addTask)("test-reschedule", later, "renewal"),
|
|
130
|
+
]);
|
|
131
|
+
(0, chai_1.expect)(results).to.deep.equal(["renewal"]);
|
|
132
|
+
(0, chai_1.expect)(await client.zscore(RedisKey, "test-reschedule:renewal")).to.equal(String(later));
|
|
133
|
+
await cleanupRedis();
|
|
134
|
+
});
|
|
135
|
+
it("should keep due tasks when reading them fails", async () => {
|
|
136
|
+
await cleanupRedis();
|
|
137
|
+
const results = [];
|
|
138
|
+
(0, index_1.setHandler)("test-read-failure", (taskInfo) => {
|
|
139
|
+
results.push(taskInfo);
|
|
140
|
+
});
|
|
141
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
142
|
+
const due = Date.now() - 1000;
|
|
143
|
+
await client.zadd(RedisKey, due, "test-read-failure:renewal");
|
|
144
|
+
if (!isMockClient(client))
|
|
145
|
+
throw new Error("The test project must use the Redis mock");
|
|
146
|
+
const mock = client;
|
|
147
|
+
const store = mock.data;
|
|
148
|
+
let failed = false;
|
|
149
|
+
const failFirstRead = (key) => {
|
|
150
|
+
if (!failed && key === RedisKey) {
|
|
151
|
+
failed = true;
|
|
152
|
+
throw new Error("ERR injected read failure");
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
mock.data = {
|
|
156
|
+
...store,
|
|
157
|
+
get: (key) => (failFirstRead(key), store.get(key)),
|
|
158
|
+
has: (key) => (failFirstRead(key), store.has(key)),
|
|
159
|
+
};
|
|
160
|
+
let rejected = false;
|
|
161
|
+
try {
|
|
162
|
+
await (0, index_1.runTasks)();
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
rejected = true;
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
mock.data = store;
|
|
169
|
+
}
|
|
170
|
+
(0, chai_1.expect)(failed).to.equal(true);
|
|
171
|
+
(0, chai_1.expect)(rejected).to.equal(true);
|
|
172
|
+
(0, chai_1.expect)(results).to.deep.equal([]);
|
|
173
|
+
(0, chai_1.expect)(await client.zscore(RedisKey, "test-read-failure:renewal")).to.equal(String(due));
|
|
174
|
+
await cleanupRedis();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
function isMockClient(client) {
|
|
178
|
+
if (!("data" in client)) {
|
|
179
|
+
return false;
|
|
67
180
|
}
|
|
181
|
+
const { data } = client;
|
|
182
|
+
return (typeof data === "object" &&
|
|
183
|
+
data !== null &&
|
|
184
|
+
"get" in data &&
|
|
185
|
+
typeof data.get === "function" &&
|
|
186
|
+
"has" in data &&
|
|
187
|
+
typeof data.has === "function");
|
|
68
188
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
189
|
+
describe("Redis Scheduler - retry logic", () => {
|
|
190
|
+
it("should retry failed tasks up to 3 times", async () => {
|
|
191
|
+
await cleanupRedis();
|
|
192
|
+
let callCount = 0;
|
|
193
|
+
(0, index_1.setHandler)("test-retry", () => {
|
|
194
|
+
callCount++;
|
|
195
|
+
throw new Error("intentional failure");
|
|
196
|
+
});
|
|
197
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
198
|
+
await client.zadd(RedisKey, Date.now() - 1000, "test-retry:retry-data");
|
|
199
|
+
await (0, index_1.runTasks)();
|
|
200
|
+
(0, chai_1.expect)(callCount).to.equal(1);
|
|
201
|
+
const retryMembers = await client.zrange(RedisKey, 0, -1);
|
|
202
|
+
(0, chai_1.expect)(retryMembers).to.have.length(1);
|
|
203
|
+
(0, chai_1.expect)(retryMembers[0]).to.match(/^RETRY-1:test-retry:retry-data$/);
|
|
204
|
+
await cleanupRedis();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
async function rejectionMessage(promise) {
|
|
80
208
|
try {
|
|
81
|
-
await
|
|
82
|
-
chai_1.expect.fail("should have thrown");
|
|
209
|
+
await promise;
|
|
83
210
|
}
|
|
84
211
|
catch (err) {
|
|
85
|
-
|
|
212
|
+
return err instanceof Error ? err.message : undefined;
|
|
86
213
|
}
|
|
87
|
-
|
|
88
|
-
async function EnableDisableListenerTest() {
|
|
89
|
-
await (0, interface_redis_scheduler_1.enableListener)();
|
|
90
|
-
await (0, interface_redis_scheduler_1.disableListener)();
|
|
91
|
-
}
|
|
92
|
-
async function EnableListenerUsesLazyConnectTest() {
|
|
93
|
-
const client = await (0, interface_redis_1.GetClient)();
|
|
94
|
-
const originalDuplicate = client.duplicate.bind(client);
|
|
95
|
-
let duplicateOptions;
|
|
96
|
-
client.duplicate = ((override) => {
|
|
97
|
-
duplicateOptions = override;
|
|
98
|
-
return originalDuplicate(override);
|
|
99
|
-
});
|
|
100
|
-
await (0, interface_redis_scheduler_1.enableListener)();
|
|
101
|
-
(0, chai_1.expect)(duplicateOptions).to.deep.include({ lazyConnect: true });
|
|
102
|
-
await (0, interface_redis_scheduler_1.disableListener)();
|
|
103
|
-
client.duplicate = originalDuplicate;
|
|
104
|
-
}
|
|
105
|
-
async function RunDueTasksTest() {
|
|
106
|
-
await cleanupRedis();
|
|
107
|
-
const results = [];
|
|
108
|
-
(0, interface_redis_scheduler_1.setHandler)("test-run", (taskInfo) => {
|
|
109
|
-
results.push(taskInfo);
|
|
110
|
-
});
|
|
111
|
-
const client = await (0, interface_redis_1.GetClient)();
|
|
112
|
-
await client.zadd(RedisKey, Date.now() - 1000, "test-run:payload1");
|
|
113
|
-
await client.zadd(RedisKey, Date.now() - 500, "test-run:payload2");
|
|
114
|
-
await (0, interface_redis_scheduler_1.runTasks)();
|
|
115
|
-
(0, chai_1.expect)(results).to.include("payload1");
|
|
116
|
-
(0, chai_1.expect)(results).to.include("payload2");
|
|
117
|
-
const remaining = await client.zrange(RedisKey, 0, -1);
|
|
118
|
-
(0, chai_1.expect)(remaining).to.have.length(0);
|
|
119
|
-
await cleanupRedis();
|
|
120
|
-
}
|
|
121
|
-
async function SkipFutureTasksTest() {
|
|
122
|
-
await cleanupRedis();
|
|
123
|
-
const results = [];
|
|
124
|
-
(0, interface_redis_scheduler_1.setHandler)("test-future", (taskInfo) => {
|
|
125
|
-
results.push(taskInfo);
|
|
126
|
-
});
|
|
127
|
-
const client = await (0, interface_redis_1.GetClient)();
|
|
128
|
-
await client.zadd(RedisKey, Date.now() + 60000, "test-future:future-data");
|
|
129
|
-
await (0, interface_redis_scheduler_1.runTasks)();
|
|
130
|
-
(0, chai_1.expect)(results).to.have.length(0);
|
|
131
|
-
const remaining = await client.zrange(RedisKey, 0, -1);
|
|
132
|
-
(0, chai_1.expect)(remaining).to.have.length(1);
|
|
133
|
-
await cleanupRedis();
|
|
134
|
-
}
|
|
135
|
-
async function RetryFailedTasksTest() {
|
|
136
|
-
await cleanupRedis();
|
|
137
|
-
let callCount = 0;
|
|
138
|
-
(0, interface_redis_scheduler_1.setHandler)("test-retry", () => {
|
|
139
|
-
callCount++;
|
|
140
|
-
throw new Error("intentional failure");
|
|
141
|
-
});
|
|
142
|
-
const client = await (0, interface_redis_1.GetClient)();
|
|
143
|
-
await client.zadd(RedisKey, Date.now() - 1000, "test-retry:retry-data");
|
|
144
|
-
await (0, interface_redis_scheduler_1.runTasks)();
|
|
145
|
-
(0, chai_1.expect)(callCount).to.equal(1);
|
|
146
|
-
const retryMembers = await client.zrange(RedisKey, 0, -1);
|
|
147
|
-
(0, chai_1.expect)(retryMembers).to.have.length(1);
|
|
148
|
-
(0, chai_1.expect)(retryMembers[0]).to.match(/^RETRY-1:test-retry:retry-data$/);
|
|
149
|
-
await cleanupRedis();
|
|
214
|
+
return undefined;
|
|
150
215
|
}
|
|
151
216
|
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,iEAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,iEAAwD;AACxD,oCAOkB;AAElB,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AAEvC,KAAK,UAAU,YAAY;IACzB,MAAM,MAAM,GAAG,MAAM,IAAA,2BAAS,GAAE,CAAC;IACjC,MAAM,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC;AAED,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QACzC,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAA,kBAAU,EAAC,eAAe,EAAE,GAAG,EAAE;YAC/B,MAAM,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O,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACxD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/docs/1.introduction.md
CHANGED
|
@@ -1,36 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
title: Redis scheduler
|
|
3
|
+
description: Schedule tasks in a Redis sorted set and run them with a listener, with the delivery, retry, and shutdown rules of each export.
|
|
4
|
+
mode: reference
|
|
5
|
+
---
|
|
2
6
|
|
|
3
7
|
## Overview
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
`@antelopejs/interface-redis-scheduler` stores tasks in a Redis sorted set, with each due timestamp as the score. A local timer checks for due tasks, and Redis pub/sub tells listeners when the schedule changes. A handler that throws is retried. The scheduler does not give exactly-once delivery.
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
The scheduler code runs in your own module. It reaches Redis through `GetClient()` from `@antelopejs/interface-redis`, so the project must load a module that implements that interface, such as `@antelopejs/redis`. Where Redis keeps its data, and whether queued entries survive a Redis restart, depends on that module's connection settings and the Redis server's persistence configuration.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
A listener takes due tasks with one Lua script that reads and removes them in a single step. Several listeners can share one queue, and each due entry goes to one of them. The entry leaves Redis before its handler runs, so a process failure after the removal and before the handler completes loses the task. Make handlers idempotent, because a retry runs the handler again after a failure that may already have had effects.
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
A listener that takes an entry whose handler name it has not registered removes the entry and does not run it, retry it, or log it. Register every handler in every process that calls `enableListener()`.
|
|
16
|
+
|
|
17
|
+
## Schedule a task safely
|
|
18
|
+
|
|
19
|
+
A task runs as expected when these four conditions hold:
|
|
20
|
+
|
|
21
|
+
1. Every process that adds, removes, or runs tasks of a type registers that type with [`setHandler`](#sethandler).
|
|
22
|
+
2. Each listener starts with [`enableListener`](#enablelistener) after its handlers are registered.
|
|
23
|
+
3. The application saves the serialized payload, then calls [`addTask`](#addtask) with a due time in milliseconds.
|
|
24
|
+
4. [`removeTask`](#removetask) receives that saved payload. A payload rebuilt with a new timestamp does not match.
|
|
25
|
+
|
|
26
|
+
{width="480"}
|
|
27
|
+
|
|
28
|
+
The scheduler fits work whose loss or repetition your application can tolerate or reconcile. It has no exactly-once execution, no durable record of which process runs a task, and no API that stops or drains processing. Read [retry logic](#retry-logic), [shutdown limits](#disablelistener), and [known limitations](#known-limitations) before you depend on it.
|
|
29
|
+
|
|
30
|
+
## Getting started
|
|
31
|
+
|
|
32
|
+
Install the package in your module:
|
|
12
33
|
|
|
13
34
|
```bash
|
|
14
35
|
npm install @antelopejs/interface-redis-scheduler
|
|
15
36
|
```
|
|
16
37
|
|
|
17
|
-
> **Note:**
|
|
38
|
+
> **Note:** `@antelopejs/interface-redis` is a peer dependency. Install it too, and load a module that implements it, such as `@antelopejs/redis`, so the scheduler can connect to Redis.
|
|
39
|
+
|
|
40
|
+
## Try one scheduled task
|
|
41
|
+
|
|
42
|
+
This example runs in an initialized application against a disposable Redis database with no other scheduler listener. It logs a reminder after about one minute. It does not send an email or charge a payment.
|
|
18
43
|
|
|
19
|
-
|
|
44
|
+
```typescript
|
|
45
|
+
import {
|
|
46
|
+
setHandler,
|
|
47
|
+
enableListener,
|
|
48
|
+
addTask,
|
|
49
|
+
} from "@antelopejs/interface-redis-scheduler";
|
|
20
50
|
|
|
21
|
-
|
|
51
|
+
setHandler("docs-reminder", (taskInfo) => {
|
|
52
|
+
console.log("Reminder:", taskInfo);
|
|
53
|
+
});
|
|
22
54
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
55
|
+
await enableListener();
|
|
56
|
+
const taskInfo = JSON.stringify({
|
|
57
|
+
jobId: "demo-001",
|
|
58
|
+
message: "Review your draft",
|
|
59
|
+
});
|
|
60
|
+
await addTask("docs-reminder", Date.now() + 60_000, taskInfo);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The process must stay alive for the reminder to appear. The due time is a Unix timestamp in milliseconds, not a delay. Save `taskInfo` if you may later remove the queued entry, and note that [removal does not guarantee cancellation](#removetask). The API cannot fully stop the timers, so end this disposable process when you are done.
|
|
64
|
+
|
|
65
|
+
## Core concepts
|
|
66
|
+
|
|
67
|
+
The scheduler has three parts:
|
|
68
|
+
|
|
69
|
+
- **Handlers** process tasks of one type. Register them with `setHandler()` before you schedule tasks of that type.
|
|
70
|
+
- **Tasks** are entries in a Redis sorted set, scored by their due time. When a task is due, a listener calls the matching handler.
|
|
71
|
+
- **Listeners** watch the sorted set and run tasks when they fall due. Start one with `enableListener()`.
|
|
26
72
|
|
|
27
73
|
## `setHandler`
|
|
28
74
|
|
|
29
|
-
|
|
75
|
+
`setHandler` registers the handler for one task type. The name identifies the type, and the callback receives the task data as a string. The registration is local to the process and makes no Redis call. `sendEmail` below stands for a function in your application. It is not a scheduler export.
|
|
30
76
|
|
|
31
77
|
```typescript
|
|
32
78
|
import { setHandler } from "@antelopejs/interface-redis-scheduler";
|
|
33
79
|
|
|
80
|
+
declare function sendEmail(message: {
|
|
81
|
+
to: string;
|
|
82
|
+
subject: string;
|
|
83
|
+
body: string;
|
|
84
|
+
}): Promise<void>;
|
|
85
|
+
|
|
34
86
|
setHandler("send-email", async (taskInfo) => {
|
|
35
87
|
const emailData = JSON.parse(taskInfo);
|
|
36
88
|
await sendEmail({
|
|
@@ -41,7 +93,7 @@ setHandler("send-email", async (taskInfo) => {
|
|
|
41
93
|
});
|
|
42
94
|
```
|
|
43
95
|
|
|
44
|
-
|
|
96
|
+
A handler name must not contain the `:` character, because the scheduler uses it as a delimiter. Otherwise `setHandler` throws an `Error` with the message ``SchedulerUtil handler name may not contain `:` ``.
|
|
45
97
|
|
|
46
98
|
### Parameters
|
|
47
99
|
|
|
@@ -52,28 +104,27 @@ Handler names must not contain the `:` character, as the scheduler uses it inter
|
|
|
52
104
|
|
|
53
105
|
## `enableListener`
|
|
54
106
|
|
|
55
|
-
|
|
107
|
+
`enableListener` starts task processing in this process. It opens a dedicated Redis subscriber connection, which receives the update messages that `addTask` publishes. It then arms a timer for the next due task, or runs the tasks that are already due.
|
|
56
108
|
|
|
57
109
|
```typescript
|
|
58
110
|
import { enableListener } from "@antelopejs/interface-redis-scheduler";
|
|
59
111
|
|
|
60
112
|
async function startApp() {
|
|
61
|
-
// Register all handlers first
|
|
113
|
+
// Register all handlers first.
|
|
62
114
|
// ...
|
|
63
115
|
|
|
64
|
-
// Then start the listener
|
|
65
116
|
await enableListener();
|
|
66
117
|
console.log("Scheduler is active");
|
|
67
118
|
}
|
|
68
119
|
```
|
|
69
120
|
|
|
70
|
-
> **Important:** Register all task handlers before
|
|
121
|
+
> **Important:** Register all task handlers before you call `enableListener()`. The listener starts processing due tasks right away.
|
|
71
122
|
|
|
72
123
|
## `disableListener`
|
|
73
124
|
|
|
74
|
-
`disableListener()` returns `Promise<void>` and only calls `quit()` on the notification subscriber. Call it only after `enableListener()` has completed
|
|
125
|
+
`disableListener()` returns `Promise<void>` and only calls `quit()` on the notification subscriber. Call it only after `enableListener()` has completed. Before that, the subscriber does not exist and the call rejects.
|
|
75
126
|
|
|
76
|
-
> **Warning:** It does not clear the pending timer, cancel running handlers, or wait for
|
|
127
|
+
> **Warning:** It does not clear the pending timer, cancel running handlers, or wait for tasks to complete. A timer that is already armed can still run tasks and arm another timer through `updateTimer()`. Do not use this function as a pause, a drain, or a guarantee that no more tasks run. The public API has no operation that stops the timer.
|
|
77
128
|
|
|
78
129
|
```typescript
|
|
79
130
|
import { disableListener } from "@antelopejs/interface-redis-scheduler";
|
|
@@ -86,56 +137,56 @@ async function stopApp() {
|
|
|
86
137
|
|
|
87
138
|
## `addTask`
|
|
88
139
|
|
|
89
|
-
|
|
140
|
+
`addTask` schedules a task for a given time. It adds the task to the Redis sorted set with the due time as its score, then publishes an update message so listeners refresh their timers. While this process runs a batch of tasks, `addTask` does not publish. That process picks up the new task when its batch ends.
|
|
90
141
|
|
|
91
142
|
```typescript
|
|
92
143
|
import { addTask } from "@antelopejs/interface-redis-scheduler";
|
|
93
144
|
|
|
94
|
-
async function scheduleReminder(
|
|
95
|
-
//
|
|
145
|
+
async function scheduleReminder(recipient: string) {
|
|
146
|
+
// Due in 3 days.
|
|
96
147
|
const dueTime = Date.now() + 3 * 24 * 60 * 60 * 1000;
|
|
97
148
|
|
|
98
149
|
const taskInfo = JSON.stringify({
|
|
99
|
-
|
|
100
|
-
|
|
150
|
+
recipient,
|
|
151
|
+
subject: "Review your draft",
|
|
152
|
+
body: "Your draft is waiting for review.",
|
|
101
153
|
createdAt: new Date().toISOString(),
|
|
102
154
|
});
|
|
103
155
|
|
|
104
156
|
await addTask("send-email", dueTime, taskInfo);
|
|
157
|
+
return taskInfo; // Persist this exact string for removal.
|
|
105
158
|
}
|
|
106
159
|
```
|
|
107
160
|
|
|
108
|
-
|
|
161
|
+
`addTask` rejects with `Unknown SchedulerUtil handler: <name>` when this process has not registered the handler name.
|
|
162
|
+
|
|
163
|
+
The pair of `handlerName` and `taskInfo` identifies the queued entry. Adding the same pair again changes its due time and does not create a second task. To keep two otherwise identical jobs apart, put a stable job ID in the payload.
|
|
109
164
|
|
|
110
165
|
### Parameters
|
|
111
166
|
|
|
112
|
-
| Parameter | Type | Description
|
|
113
|
-
| ------------- | -------- |
|
|
114
|
-
| `handlerName` | `string` | The registered handler name that processes this task
|
|
115
|
-
| `dueTime` | `number` | Unix timestamp in milliseconds when the task
|
|
116
|
-
| `taskInfo` | `string` | Data passed to the handler
|
|
167
|
+
| Parameter | Type | Description |
|
|
168
|
+
| ------------- | -------- | --------------------------------------------------------- |
|
|
169
|
+
| `handlerName` | `string` | The registered handler name that processes this task |
|
|
170
|
+
| `dueTime` | `number` | Unix timestamp in milliseconds when the task is due |
|
|
171
|
+
| `taskInfo` | `string` | Data passed to the handler, usually a JSON-encoded string |
|
|
117
172
|
|
|
118
173
|
## `removeTask`
|
|
119
174
|
|
|
120
|
-
|
|
175
|
+
`removeTask` removes the original queued entry if it is still present. Pass the saved `taskInfo` string that `scheduleReminder` returned. Do not rebuild the JSON.
|
|
121
176
|
|
|
122
177
|
```typescript
|
|
123
178
|
import { removeTask } from "@antelopejs/interface-redis-scheduler";
|
|
124
179
|
|
|
125
|
-
async function
|
|
126
|
-
|
|
127
|
-
userId,
|
|
128
|
-
type: "password_reminder",
|
|
129
|
-
createdAt: "2025-04-05T12:00:00.000Z", // Must match exactly
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
await removeTask("send-email", taskInfo);
|
|
180
|
+
async function removeQueuedReminder(savedTaskInfo: string) {
|
|
181
|
+
await removeTask("send-email", savedTaskInfo);
|
|
133
182
|
}
|
|
134
183
|
```
|
|
135
184
|
|
|
136
|
-
|
|
185
|
+
`removeTask` rejects with `Unknown SchedulerUtil handler: <name>` when this process has not registered the handler name.
|
|
137
186
|
|
|
138
|
-
> **Warning:** The `taskInfo` must
|
|
187
|
+
> **Warning:** The `taskInfo` must match the original string exactly. If the serialized JSON differs in key order or whitespace, nothing is removed and no error is raised.
|
|
188
|
+
|
|
189
|
+
Removal targets the original queued entry only. It does not stop a running handler, and it does not remove a retry stored with a `RETRY-` prefix. If a cancellation must survive races and retries, make the handler check cancellation state that your application owns before it applies effects.
|
|
139
190
|
|
|
140
191
|
### Parameters
|
|
141
192
|
|
|
@@ -144,60 +195,62 @@ The function throws an error if the specified handler name has not been register
|
|
|
144
195
|
| `handlerName` | `string` | The handler name associated with the task |
|
|
145
196
|
| `taskInfo` | `string` | The exact task info string used when adding the task |
|
|
146
197
|
|
|
147
|
-
## Retry
|
|
148
|
-
|
|
149
|
-
The scheduler automatically retries failed tasks. When a handler throws an error, the scheduler reschedules the task with a retry counter.
|
|
198
|
+
## Retry logic
|
|
150
199
|
|
|
151
|
-
|
|
152
|
-
- **Retry delay:** 5 seconds between each attempt
|
|
153
|
-
- **Behavior on exhaustion:** After 3 failed retries, the task is discarded and the error is logged to the console
|
|
200
|
+
The scheduler retries failed tasks with no extra code. When a handler throws or its promise rejects, the scheduler logs the error with `Logging.Error` and queues the task again with a retry counter.
|
|
154
201
|
|
|
155
|
-
|
|
202
|
+
- **Maximum retries.** 3 retries after the first attempt, so 4 attempts in total.
|
|
203
|
+
- **Retry delay.** Each retry is due 5 seconds after the attempt that failed.
|
|
204
|
+
- **Exhaustion.** After the third retry fails, the scheduler logs the error and discards the task.
|
|
156
205
|
|
|
157
206
|
```typescript
|
|
158
207
|
import { setHandler } from "@antelopejs/interface-redis-scheduler";
|
|
159
208
|
|
|
160
|
-
|
|
161
|
-
|
|
209
|
+
declare function refreshSummary(data: unknown): Promise<void>;
|
|
210
|
+
|
|
211
|
+
// If this handler throws, the scheduler retries up to 3 times.
|
|
212
|
+
setHandler("refresh-summary", async (taskInfo) => {
|
|
162
213
|
const data = JSON.parse(taskInfo);
|
|
163
|
-
await
|
|
164
|
-
// On failure: retry after 5s, then 5s, then 5s, then discard
|
|
214
|
+
await refreshSummary(data);
|
|
215
|
+
// On failure: retry after 5s, then 5s, then 5s, then discard.
|
|
165
216
|
});
|
|
166
217
|
```
|
|
167
218
|
|
|
168
|
-
|
|
219
|
+
`refreshSummary` is an application function that recomputes a replaceable summary. Choose work that is safe to retry and idempotent, because a retry does not prove that the failed attempt had no effect. Do not use this pattern as a durable payment-processing queue.
|
|
220
|
+
|
|
221
|
+
## Redis storage
|
|
169
222
|
|
|
170
|
-
The scheduler uses
|
|
223
|
+
The scheduler uses one Redis sorted set with the key `SchedulerUtil.Tasks`. Each entry has the form `handlerName:taskInfo`, and its score is the due timestamp in milliseconds.
|
|
171
224
|
|
|
172
|
-
|
|
225
|
+
A retried task has the form `RETRY-{count}:handlerName:taskInfo`, where `{count}` is the number of the retry, from 1 to 3.
|
|
173
226
|
|
|
174
|
-
The scheduler also uses a Redis pub/sub channel named `SchedulerUtil`
|
|
227
|
+
The scheduler also uses a Redis pub/sub channel named `SchedulerUtil`. `addTask` publishes the message `update` on it, and each listener that receives it refreshes its timer. The messages do not assign tasks to a listener. The Lua script that takes due tasks does that.
|
|
175
228
|
|
|
176
229
|
## `updateTimer`
|
|
177
230
|
|
|
178
|
-
|
|
231
|
+
`updateTimer` reads the first queued task. If that task is already due, `updateTimer` runs the due tasks. Otherwise it arms a timer for the task's due time, capped at 24 hours. A listener calls `updateTimer` when it starts, when it receives an update message, and after each batch of tasks. While this process runs a batch, `updateTimer` returns without doing anything. You do not need to call it in normal usage.
|
|
179
232
|
|
|
180
233
|
```typescript
|
|
181
234
|
import { updateTimer } from "@antelopejs/interface-redis-scheduler";
|
|
182
235
|
|
|
183
|
-
// Force a timer refresh (advanced usage)
|
|
236
|
+
// Force a timer refresh (advanced usage).
|
|
184
237
|
await updateTimer();
|
|
185
238
|
```
|
|
186
239
|
|
|
187
240
|
## `runTasks`
|
|
188
241
|
|
|
189
|
-
|
|
242
|
+
`runTasks` takes every task that is due and runs it. It removes the due tasks from Redis in one step, then calls their handlers one after another, earliest due time first. A task whose handler is not registered in this process is dropped. The retry logic applies to each handler that fails. When the batch ends, `runTasks` calls `updateTimer`. The timer calls `runTasks` when it fires, so you do not need to call it in normal usage.
|
|
190
243
|
|
|
191
244
|
```typescript
|
|
192
245
|
import { runTasks } from "@antelopejs/interface-redis-scheduler";
|
|
193
246
|
|
|
194
|
-
//
|
|
247
|
+
// Run the due tasks now (advanced usage).
|
|
195
248
|
await runTasks();
|
|
196
249
|
```
|
|
197
250
|
|
|
198
|
-
## Complete
|
|
251
|
+
## Complete example
|
|
199
252
|
|
|
200
|
-
|
|
253
|
+
This sketch registers handlers, starts the listener, schedules tasks, and closes the subscriber. `sendEmail`, `deleteSession`, and `refreshSummary` in these examples stand for application functions you supply. They are not scheduler exports. The example needs a configured Redis implementation and does not start a service from this page.
|
|
201
254
|
|
|
202
255
|
```typescript
|
|
203
256
|
import {
|
|
@@ -208,7 +261,14 @@ import {
|
|
|
208
261
|
removeTask,
|
|
209
262
|
} from "@antelopejs/interface-redis-scheduler";
|
|
210
263
|
|
|
211
|
-
|
|
264
|
+
declare function sendEmail(
|
|
265
|
+
to: string,
|
|
266
|
+
subject: string,
|
|
267
|
+
body: string,
|
|
268
|
+
): Promise<void>;
|
|
269
|
+
declare function deleteSession(sessionId: string): Promise<void>;
|
|
270
|
+
|
|
271
|
+
// 1. Register task handlers.
|
|
212
272
|
setHandler("send-email", async (taskInfo) => {
|
|
213
273
|
const data = JSON.parse(taskInfo);
|
|
214
274
|
await sendEmail(data.to, data.subject, data.body);
|
|
@@ -219,14 +279,14 @@ setHandler("cleanup-session", async (taskInfo) => {
|
|
|
219
279
|
await deleteSession(sessionId);
|
|
220
280
|
});
|
|
221
281
|
|
|
222
|
-
// 2. Start the listener
|
|
282
|
+
// 2. Start the listener.
|
|
223
283
|
async function start() {
|
|
224
284
|
await enableListener();
|
|
225
285
|
}
|
|
226
286
|
|
|
227
|
-
// 3. Schedule tasks from your application logic
|
|
287
|
+
// 3. Schedule tasks from your application logic.
|
|
228
288
|
async function onUserSignup(userId: string, email: string) {
|
|
229
|
-
// Send a welcome email in 1 hour
|
|
289
|
+
// Send a welcome email in 1 hour.
|
|
230
290
|
const dueTime = Date.now() + 60 * 60 * 1000;
|
|
231
291
|
await addTask(
|
|
232
292
|
"send-email",
|
|
@@ -240,13 +300,22 @@ async function onUserSignup(userId: string, email: string) {
|
|
|
240
300
|
}
|
|
241
301
|
|
|
242
302
|
async function onUserLogout(sessionId: string) {
|
|
243
|
-
// Clean up session data in 24 hours
|
|
303
|
+
// Clean up session data in 24 hours.
|
|
244
304
|
const dueTime = Date.now() + 24 * 60 * 60 * 1000;
|
|
245
305
|
await addTask("cleanup-session", dueTime, JSON.stringify({ sessionId }));
|
|
246
306
|
}
|
|
247
307
|
|
|
248
|
-
// 4. Close notifications on shutdown
|
|
308
|
+
// 4. Close notifications on shutdown. Pending timers and handlers may continue.
|
|
249
309
|
async function shutdown() {
|
|
250
310
|
await disableListener();
|
|
251
311
|
}
|
|
252
312
|
```
|
|
313
|
+
|
|
314
|
+
## Known limitations
|
|
315
|
+
|
|
316
|
+
These behaviours are tracked as open issues:
|
|
317
|
+
|
|
318
|
+
- Two batches can run at the same time on one listener, so two handlers of one process can overlap ([#39](https://github.com/AntelopeJS/interface-redis-scheduler/issues/39)).
|
|
319
|
+
- When `runTasks` rejects, for example because Redis fails while it takes due tasks or writes a retry, the process keeps its internal lock. That listener's `updateTimer` then returns without arming a timer ([#27](https://github.com/AntelopeJS/interface-redis-scheduler/issues/27)).
|
|
320
|
+
- When writing a retry fails in the middle of a batch, the batch's remaining tasks are lost. They were already removed from Redis ([#29](https://github.com/AntelopeJS/interface-redis-scheduler/issues/29)).
|
|
321
|
+
- When `removeTask` deletes the first queued task while `updateTimer` reads it, no timer is armed, and the remaining tasks wait for the next update message ([#38](https://github.com/AntelopeJS/interface-redis-scheduler/issues/38)).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="480" height="760" viewBox="0 0 480 760" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">Task delivery and the in-flight gap</title>
|
|
3
|
+
<desc id="desc">A timer reads and removes due tasks from a sorted set in one Lua script before calling handlers. Successful handlers finish. Thrown errors requeue after five seconds, up to three retries. A crash after removal can lose work; pub/sub only refreshes timers.</desc>
|
|
4
|
+
<defs><marker id="arrow" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto"><path d="M0 0 8 4 0 8" fill="#627d98"/></marker></defs>
|
|
5
|
+
<rect width="480" height="760" rx="16" fill="#f4f7fb"/>
|
|
6
|
+
<g font-family="system-ui, sans-serif" fill="#17324d" font-size="18">
|
|
7
|
+
<text x="24" y="36" font-size="24" font-weight="700">Remove first. Run the handler.</text><text x="24" y="70">Every listener registers every handler</text><text x="24" y="99">Application-owned recovery</text>
|
|
8
|
+
<rect x="24" y="126" width="400" height="86" rx="10" fill="#e2edf8" stroke="#b0c9e0"/><text x="44" y="160" font-size="22" font-weight="700">Queued in Redis</text><text x="44" y="190">Score = due time (milliseconds)</text>
|
|
9
|
+
<path d="M224 212V246" stroke="#627d98" stroke-width="2" marker-end="url(#arrow)"/>
|
|
10
|
+
<rect x="24" y="258" width="400" height="86" rx="10" fill="#fff0cf"/><text x="44" y="292" font-size="22" font-weight="700">Read + remove due tasks</text><text x="44" y="322">One Lua script, one listener per task</text>
|
|
11
|
+
<path d="M224 344V378" stroke="#627d98" stroke-width="2" marker-end="url(#arrow)"/>
|
|
12
|
+
<rect x="24" y="390" width="400" height="86" rx="10" fill="#17324d"/><text x="44" y="424" fill="#fff" font-size="22" font-weight="700">Run handler</text><text x="44" y="454" fill="#d5e5f3">Success → done</text>
|
|
13
|
+
<path d="M424 433H448V169H424" fill="none" stroke="#627d98" stroke-width="2" stroke-dasharray="5 5" marker-end="url(#arrow)"/>
|
|
14
|
+
<text x="24" y="514" font-weight="600">Dashed path: handler throws</text><text x="24" y="544">Retry after 5s · at most 3 retries</text>
|
|
15
|
+
<rect x="24" y="573" width="432" height="164" rx="8" fill="#fbe6e2"/>
|
|
16
|
+
<text x="44" y="606" font-size="20" font-weight="600">Crash after removal?</text><text x="44" y="635">The in-flight task can be lost.</text><text x="44" y="669" font-size="16">Pub/sub refreshes timers, not ownership.</text><text x="44" y="699" font-size="16">disableListener() closes notifications only.</text>
|
|
17
|
+
</g>
|
|
18
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-redis-scheduler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "AntelopeJS interface for scheduling tasks on Redis, with retries on failure",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -45,7 +45,15 @@
|
|
|
45
45
|
"release": "pnpm run lint && pnpm run prepack && release-it",
|
|
46
46
|
"test": "pnpm run build && ajs module test .",
|
|
47
47
|
"format:check": "oxfmt --check .",
|
|
48
|
-
"knip": "knip"
|
|
48
|
+
"knip": "knip",
|
|
49
|
+
"prepare": "if git rev-parse --is-inside-work-tree >/dev/null 2>&1 && command -v lefthook >/dev/null 2>&1; then lefthook install; fi",
|
|
50
|
+
"checks": "antelopejs-checks",
|
|
51
|
+
"size": "antelopejs-check-size",
|
|
52
|
+
"sync": "antelopejs-sync",
|
|
53
|
+
"sync:check": "antelopejs-sync --check",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"suppressions": "antelopejs-suppressions",
|
|
56
|
+
"suppressions:update": "antelopejs-suppressions --update"
|
|
49
57
|
},
|
|
50
58
|
"dependencies": {
|
|
51
59
|
"ioredis": "^5.10.1"
|
|
@@ -54,13 +62,14 @@
|
|
|
54
62
|
"@antelopejs/core": "^1.16.0",
|
|
55
63
|
"@antelopejs/interface-core": "^0.2.4",
|
|
56
64
|
"@antelopejs/interface-redis": "^0.0.9",
|
|
57
|
-
"@antelopejs/tooling-configs": "^0.
|
|
65
|
+
"@antelopejs/tooling-configs": "^0.2.18",
|
|
58
66
|
"@types/chai": "^4.3.20",
|
|
59
67
|
"@types/mocha": "^10.0.10",
|
|
60
68
|
"@types/node": "^22.19.15",
|
|
61
69
|
"chai": "^4.5.0",
|
|
62
70
|
"eslint-plugin-perfectionist": "^5.11.0",
|
|
63
71
|
"knip": "^6.34.0",
|
|
72
|
+
"lefthook": "^2.2.2",
|
|
64
73
|
"oxfmt": "^0.66.0",
|
|
65
74
|
"oxlint": "1.81.0",
|
|
66
75
|
"oxlint-tsgolint": "^7.0.2001",
|
|
@@ -78,6 +87,9 @@
|
|
|
78
87
|
"test": "src/antelope.test.ts",
|
|
79
88
|
"skills": [
|
|
80
89
|
"./skills"
|
|
81
|
-
]
|
|
90
|
+
],
|
|
91
|
+
"docs": {
|
|
92
|
+
"standard": true
|
|
93
|
+
}
|
|
82
94
|
}
|
|
83
95
|
}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: redis-scheduler-interface
|
|
3
|
-
description: Distributed Redis-backed task scheduling for AntelopeJS
|
|
3
|
+
description: Distributed Redis-backed task scheduling for AntelopeJS. Register named handlers, schedule tasks at a due timestamp in a Redis sorted set, and execute them with automatic retries; listeners across instances claim due tasks atomically, and pub/sub only re-arms their timers. Use when code imports '@antelopejs/interface-redis-scheduler', when a task involves scheduling delayed/deferred jobs, reminders, or background work in an AntelopeJS module, or when symbols like setHandler, addTask, removeTask, enableListener, disableListener, or the SchedulerUtil.Tasks Redis key appear.
|
|
4
4
|
category: antelopejs-interface
|
|
5
5
|
tags: [antelopejs, redis, scheduler, tasks, background-jobs]
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Redis Scheduler Interface
|
|
9
9
|
|
|
10
|
-
Distributed task scheduler on top of Redis
|
|
11
|
-
(`SchedulerUtil.Tasks`) scored by their due timestamp
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
Distributed task scheduler on top of Redis. Tasks live in one sorted set
|
|
11
|
+
(`SchedulerUtil.Tasks`), scored by their due timestamp. A listener takes the
|
|
12
|
+
due tasks with one Lua script that reads and removes them in a single step, so
|
|
13
|
+
each due entry goes to exactly one listener, and several listeners can share
|
|
14
|
+
the queue. The `SchedulerUtil` pub/sub channel only carries an `update`
|
|
15
|
+
message that tells listeners to re-arm their timers; it does not decide who
|
|
16
|
+
runs a task.
|
|
17
|
+
|
|
18
|
+
Mental model: this is a consumer-side utility, not a proxied service. All
|
|
19
|
+
exported functions run in your own module. Redis access goes through
|
|
20
|
+
`GetClient()` from `@antelopejs/interface-redis` (`setHandler` itself is local
|
|
21
|
+
and makes no Redis call). There is no provider to write with
|
|
22
|
+
`ImplementInterface`. A Redis interface implementation (for example the
|
|
18
23
|
`@antelopejs/redis` module) must be loaded in the app.
|
|
19
24
|
|
|
20
25
|
## Imports
|
|
@@ -31,8 +36,8 @@ import {
|
|
|
31
36
|
} from "@antelopejs/interface-redis-scheduler";
|
|
32
37
|
```
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
execution loop
|
|
39
|
+
`updateTimer` and `runTasks` are also exported, but they belong to the internal
|
|
40
|
+
execution loop. Call them only in tests or advanced scenarios.
|
|
36
41
|
|
|
37
42
|
## Consumption example
|
|
38
43
|
|
|
@@ -66,28 +71,43 @@ await disableListener();
|
|
|
66
71
|
|
|
67
72
|
## Gotchas
|
|
68
73
|
|
|
69
|
-
- Handler names must not contain
|
|
74
|
+
- Handler names must not contain `:`, which delimits the sorted-set member
|
|
70
75
|
format `handlerName:taskInfo`. `setHandler` throws otherwise.
|
|
71
|
-
- `addTask` and `removeTask`
|
|
72
|
-
current process.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
- `addTask` and `removeTask` reject with `Unknown SchedulerUtil handler: <name>`
|
|
77
|
+
for a handler name not registered in the current process. Call `setHandler`
|
|
78
|
+
before you schedule.
|
|
79
|
+
- Register every handler in every listener process. A listener that claims a
|
|
80
|
+
due entry whose handler it has not registered drops the entry: it does not
|
|
81
|
+
run it, retry it or log it.
|
|
82
|
+
- Register all handlers before `enableListener()`. The listener checks for due
|
|
83
|
+
tasks as soon as it starts.
|
|
84
|
+
- A claimed entry is removed from Redis before its handler runs. If the
|
|
85
|
+
process stops during the run, the task is lost. There is no exactly-once
|
|
86
|
+
execution.
|
|
87
|
+
- A batch runs its handlers one after another, earliest due time first.
|
|
88
|
+
- `taskInfo` is a plain string. Serialize and parse it (typically JSON)
|
|
89
|
+
yourself.
|
|
90
|
+
- `removeTask` needs the exact original `taskInfo` string. A JSON payload with
|
|
91
|
+
a different key order or whitespace does not match, and nothing is removed.
|
|
92
|
+
- A handler that throws or rejects is retried up to 3 times. Each retry is due
|
|
93
|
+
5 seconds after the attempt that failed, and its member becomes
|
|
94
|
+
`RETRY-{n}:handlerName:taskInfo`. After the third retry fails, the task is
|
|
95
|
+
discarded. Every failure is logged through interface-core `Logging.Error`.
|
|
96
|
+
- The listener's timer waits at most 24 hours before it checks again.
|
|
81
97
|
- `enableListener` duplicates the shared Redis client into a dedicated
|
|
82
|
-
subscriber connection
|
|
83
|
-
- `disableListener` only quits the subscriber connection
|
|
84
|
-
pending
|
|
85
|
-
|
|
98
|
+
subscriber connection. `disableListener` quits that subscriber.
|
|
99
|
+
- `disableListener` only quits the subscriber connection. It does not clear
|
|
100
|
+
the pending timer, cancel running handlers, or wait for tasks to complete.
|
|
101
|
+
An armed timer keeps running due tasks and arming the next timer through
|
|
102
|
+
`updateTimer()`, so tasks can keep running after it returns. Do not use it as
|
|
103
|
+
a pause, a drain, or a guarantee that no more tasks run: the public API has
|
|
104
|
+
no operation that stops the timer. It rejects if `enableListener` was never
|
|
105
|
+
called.
|
|
86
106
|
- Peer interfaces `@antelopejs/interface-core` and `@antelopejs/interface-redis`
|
|
87
107
|
must be installed alongside this package.
|
|
88
108
|
|
|
89
109
|
## Deeper reference
|
|
90
110
|
|
|
91
|
-
See this package's `docs/1.introduction.md` (
|
|
92
|
-
|
|
93
|
-
and `dist/index.d.ts`. Do not duplicate them here.
|
|
111
|
+
See this package's `docs/1.introduction.md` (overview, getting started, core
|
|
112
|
+
concepts, one section per function, retry logic, Redis storage, complete
|
|
113
|
+
example, known limitations) and `dist/index.d.ts`. Do not duplicate them here.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"cases": [
|
|
4
|
+
{
|
|
5
|
+
"id": "redis-scheduler-interface-delayed-job",
|
|
6
|
+
"area": "framework",
|
|
7
|
+
"style": "clean",
|
|
8
|
+
"prompt": "In my AntelopeJS module, schedule a reminder email to run 24 hours after a booking is created, and have it run on whichever instance is listening.",
|
|
9
|
+
"expect": {
|
|
10
|
+
"skills": ["redis-scheduler-interface"],
|
|
11
|
+
"acceptable": [
|
|
12
|
+
"redis-interface",
|
|
13
|
+
"ajs-consume-interface",
|
|
14
|
+
"antelopejs"
|
|
15
|
+
],
|
|
16
|
+
"mustMention": ["setHandler", "addTask"]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "redis-scheduler-interface-delayed-job-casual",
|
|
21
|
+
"area": "framework",
|
|
22
|
+
"style": "casual",
|
|
23
|
+
"prompt": "need to run a job later, like in an hour, across my instances. whats the antelope way",
|
|
24
|
+
"expect": {
|
|
25
|
+
"skills": ["redis-scheduler-interface"],
|
|
26
|
+
"acceptable": [
|
|
27
|
+
"redis-interface",
|
|
28
|
+
"ajs-consume-interface",
|
|
29
|
+
"antelopejs"
|
|
30
|
+
],
|
|
31
|
+
"mustMention": ["addTask"]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "redis-scheduler-interface-redis-neighbour",
|
|
36
|
+
"area": "framework",
|
|
37
|
+
"style": "clean",
|
|
38
|
+
"prompt": "Cache the result of an expensive lookup in Redis for 10 minutes from my AntelopeJS module.",
|
|
39
|
+
"expect": {
|
|
40
|
+
"skills": ["redis-interface"],
|
|
41
|
+
"acceptable": ["ajs-consume-interface", "antelopejs"],
|
|
42
|
+
"avoid": ["redis-scheduler-interface"]
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "redis-scheduler-interface-two-listeners",
|
|
47
|
+
"area": "framework",
|
|
48
|
+
"style": "clean",
|
|
49
|
+
"prompt": "Three instances of my module call enableListener from @antelopejs/interface-redis-scheduler. Can a due task run on more than one of them?",
|
|
50
|
+
"expect": {
|
|
51
|
+
"skills": ["redis-scheduler-interface"],
|
|
52
|
+
"acceptable": ["redis-interface", "antelopejs"],
|
|
53
|
+
"mustMention": ["Lua"]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|