@antelopejs/interface-redis-scheduler 0.0.7 → 0.0.9
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 +87 -13
- package/dist/antelope.test.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +16 -7
- package/dist/index.js.map +1 -1
- package/dist/tests/index.test.js +81 -20
- package/dist/tests/index.test.js.map +1 -1
- package/docs/1.introduction.md +84 -35
- package/docs/assets/task-delivery.svg +18 -0
- package/package.json +42 -19
package/README.md
CHANGED
|
@@ -1,28 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
# Interface Redis Scheduler
|
|
1
|
+
# @antelopejs/interface-redis-scheduler
|
|
4
2
|
|
|
5
3
|
<div align="center">
|
|
6
|
-
<a href="https://www.npmjs.com/package/@antelopejs/interface-redis-scheduler"><img src="https://img.shields.io/npm/v/@antelopejs/interface-redis-scheduler?style=for-the-badge&labelColor=000000&color=000000"
|
|
7
|
-
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/
|
|
8
|
-
<a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000"
|
|
9
|
-
<a href="
|
|
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/sjK28QHrA7"><img 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 alt="Docs" src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000"></a>
|
|
10
8
|
</div>
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
Task scheduling on Redis for AntelopeJS: schedule a task for a given time, and the application runs it when it is due, with up to three retries on failure.
|
|
11
|
+
|
|
12
|
+
## What it offers
|
|
13
|
+
|
|
14
|
+
- `setHandler` registers the function that runs one kind of task.
|
|
15
|
+
- `addTask` schedules a task for a Unix timestamp in milliseconds; `removeTask` cancels it.
|
|
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 restarts and every instance of the application sees the same queue.
|
|
18
|
+
|
|
19
|
+
## Implementations
|
|
20
|
+
|
|
21
|
+
| Module | Notes |
|
|
22
|
+
| ---------------------------------------------------------- | --------------------------------------------- |
|
|
23
|
+
| [`@antelopejs/redis`](https://github.com/AntelopeJS/redis) | Also implements `@antelopejs/interface-redis` |
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
Add the interface to the module that schedules tasks:
|
|
13
28
|
|
|
14
|
-
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @antelopejs/interface-redis-scheduler
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then add the implementation to the project:
|
|
15
34
|
|
|
16
35
|
```bash
|
|
17
|
-
|
|
36
|
+
ajs project modules add @antelopejs/redis
|
|
18
37
|
```
|
|
19
38
|
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { Logging } from "@antelopejs/interface-core/logging";
|
|
43
|
+
import {
|
|
44
|
+
addTask,
|
|
45
|
+
disableListener,
|
|
46
|
+
enableListener,
|
|
47
|
+
setHandler,
|
|
48
|
+
} from "@antelopejs/interface-redis-scheduler";
|
|
49
|
+
|
|
50
|
+
const ONE_HOUR_MS = 60 * 60 * 1000;
|
|
51
|
+
|
|
52
|
+
setHandler("overdue-notice", async (taskInfo) => {
|
|
53
|
+
const { memberId } = JSON.parse(taskInfo);
|
|
54
|
+
Logging.Info(`Remind member ${memberId}`);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export async function start() {
|
|
58
|
+
await enableListener();
|
|
59
|
+
await addTask(
|
|
60
|
+
"overdue-notice",
|
|
61
|
+
Date.now() + ONE_HOUR_MS,
|
|
62
|
+
JSON.stringify({ memberId: "M-1042" }),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function stop() {
|
|
67
|
+
await disableListener();
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Register a handler before you schedule tasks for it: `addTask` throws for an unknown handler name.
|
|
72
|
+
|
|
73
|
+
`disableListener()` is not a full shutdown or pause: a pending timer and running handlers can continue processing tasks. See the [current lifecycle and delivery limitations](./docs/1.introduction.md#disablelistener) before using it for shutdown.
|
|
74
|
+
|
|
20
75
|
## Documentation
|
|
21
76
|
|
|
22
|
-
|
|
77
|
+
- [Introduction and scheduler reference](./docs/1.introduction.md)
|
|
78
|
+
|
|
79
|
+
## Compatibility
|
|
80
|
+
|
|
81
|
+
Requires AntelopeJS core `1.x` and the following peer dependencies:
|
|
23
82
|
|
|
24
|
-
-
|
|
83
|
+
<!-- docs-compat: ./package.json#peerDependencies -->
|
|
84
|
+
|
|
85
|
+
| Package | Range |
|
|
86
|
+
| ----------------------------- | ---------------- |
|
|
87
|
+
| `@antelopejs/interface-core` | `>=0.2.4 <1.0.0` |
|
|
88
|
+
| `@antelopejs/interface-redis` | `>=0.0.9 <1.0.0` |
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
Read [CONTRIBUTING.md](./CONTRIBUTING.md) before you open a pull request. The local checks are:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
pnpm install
|
|
96
|
+
pnpm lint
|
|
97
|
+
pnpm test
|
|
98
|
+
```
|
|
25
99
|
|
|
26
100
|
## License
|
|
27
101
|
|
|
28
|
-
|
|
102
|
+
[Apache-2.0](./LICENSE)
|
package/dist/antelope.test.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -46,8 +46,9 @@ export declare function setHandler(handlerName: string, handler: HandlerType): v
|
|
|
46
46
|
*/
|
|
47
47
|
export declare function enableListener(): Promise<void>;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
* This
|
|
49
|
+
* Closes the Redis notification subscriber after enableListener() has completed.
|
|
50
|
+
* This does not clear the pending timer, stop running handlers, or await task completion.
|
|
51
|
+
* Tasks may continue to execute and schedule further timer checks; this is not a full shutdown.
|
|
51
52
|
*
|
|
52
53
|
* @example
|
|
53
54
|
* ```typescript
|
|
@@ -56,7 +57,7 @@ export declare function enableListener(): Promise<void>;
|
|
|
56
57
|
* // During application shutdown
|
|
57
58
|
* async function stopApp() {
|
|
58
59
|
* await disableListener();
|
|
59
|
-
* console.log('
|
|
60
|
+
* console.log('Scheduler notification subscriber closed; task processing may continue');
|
|
60
61
|
* }
|
|
61
62
|
* ```
|
|
62
63
|
*/
|
package/dist/index.js
CHANGED
|
@@ -7,9 +7,9 @@ exports.addTask = addTask;
|
|
|
7
7
|
exports.removeTask = removeTask;
|
|
8
8
|
exports.updateTimer = updateTimer;
|
|
9
9
|
exports.runTasks = runTasks;
|
|
10
|
-
const interface_core_1 = require("@antelopejs/interface-core");
|
|
11
|
-
const logging_1 = require("@antelopejs/interface-core/logging");
|
|
12
10
|
const interface_redis_1 = require("@antelopejs/interface-redis");
|
|
11
|
+
const logging_1 = require("@antelopejs/interface-core/logging");
|
|
12
|
+
const interface_core_1 = require("@antelopejs/interface-core");
|
|
13
13
|
/** Redis key used to store scheduled tasks in a sorted set */
|
|
14
14
|
const RedisKey = "SchedulerUtil.Tasks";
|
|
15
15
|
const SchedulerChannel = "SchedulerUtil";
|
|
@@ -99,8 +99,9 @@ async function enableListener() {
|
|
|
99
99
|
void updateTimer();
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
103
|
-
* This
|
|
102
|
+
* Closes the Redis notification subscriber after enableListener() has completed.
|
|
103
|
+
* This does not clear the pending timer, stop running handlers, or await task completion.
|
|
104
|
+
* Tasks may continue to execute and schedule further timer checks; this is not a full shutdown.
|
|
104
105
|
*
|
|
105
106
|
* @example
|
|
106
107
|
* ```typescript
|
|
@@ -109,7 +110,7 @@ async function enableListener() {
|
|
|
109
110
|
* // During application shutdown
|
|
110
111
|
* async function stopApp() {
|
|
111
112
|
* await disableListener();
|
|
112
|
-
* console.log('
|
|
113
|
+
* console.log('Scheduler notification subscriber closed; task processing may continue');
|
|
113
114
|
* }
|
|
114
115
|
* ```
|
|
115
116
|
*/
|
|
@@ -216,6 +217,15 @@ async function updateTimer() {
|
|
|
216
217
|
}
|
|
217
218
|
}
|
|
218
219
|
}
|
|
220
|
+
const TakeDueTasksScript = `
|
|
221
|
+
local due = redis.call("ZRANGEBYSCORE", KEYS[1], 0, ARGV[1])
|
|
222
|
+
redis.call("ZREMRANGEBYSCORE", KEYS[1], 0, ARGV[1])
|
|
223
|
+
return due
|
|
224
|
+
`;
|
|
225
|
+
async function takeDueTasks(client) {
|
|
226
|
+
const tasks = await client.eval(TakeDueTasksScript, 1, RedisKey, Date.now());
|
|
227
|
+
return Array.isArray(tasks) ? tasks.map(String) : [];
|
|
228
|
+
}
|
|
219
229
|
/**
|
|
220
230
|
* Executes all due tasks
|
|
221
231
|
* This is called internally by the timer when tasks are due for execution
|
|
@@ -224,9 +234,8 @@ async function updateTimer() {
|
|
|
224
234
|
async function runTasks() {
|
|
225
235
|
locked = true;
|
|
226
236
|
const client = await (0, interface_redis_1.GetClient)();
|
|
227
|
-
const tasks = await client
|
|
237
|
+
const tasks = await takeDueTasks(client);
|
|
228
238
|
if (tasks.length > 0) {
|
|
229
|
-
await client.zrem(RedisKey, ...tasks);
|
|
230
239
|
for (const task of tasks) {
|
|
231
240
|
const m = task.match(RetryPattern);
|
|
232
241
|
try {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index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C,IAAI,CAAC;gBACH,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC5B,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,iBAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACnB,IAAI,CAAC,EAAE,CAAC;oBACN,MAAM,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBACjD,IAAI,UAAU,GAAG,UAAU,EAAE,CAAC;wBAC5B,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;oBACJ,CAAC;gBACH,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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const interface_redis_1 = require("@antelopejs/interface-redis");
|
|
4
|
-
const interface_redis_scheduler_1 = require("@antelopejs/interface-redis-scheduler");
|
|
5
3
|
const chai_1 = require("chai");
|
|
4
|
+
const interface_redis_1 = require("@antelopejs/interface-redis");
|
|
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)();
|
|
@@ -27,20 +27,81 @@ describe("Redis Scheduler - enableListener / disableListener", () => {
|
|
|
27
27
|
describe("Redis Scheduler - runTasks", () => {
|
|
28
28
|
it("should execute due tasks", async () => RunDueTasksTest());
|
|
29
29
|
it("should not execute future tasks", async () => SkipFutureTasksTest());
|
|
30
|
+
it("should keep a task rescheduled while due tasks are collected", async () => {
|
|
31
|
+
await cleanupRedis();
|
|
32
|
+
const results = [];
|
|
33
|
+
(0, index_1.setHandler)("test-reschedule", (taskInfo) => {
|
|
34
|
+
results.push(taskInfo);
|
|
35
|
+
});
|
|
36
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
37
|
+
const later = Date.now() + 60000;
|
|
38
|
+
await client.zadd(RedisKey, Date.now() - 1000, "test-reschedule:renewal");
|
|
39
|
+
await Promise.all([
|
|
40
|
+
(0, index_1.runTasks)(),
|
|
41
|
+
(0, index_1.addTask)("test-reschedule", later, "renewal"),
|
|
42
|
+
]);
|
|
43
|
+
(0, chai_1.expect)(results).to.deep.equal(["renewal"]);
|
|
44
|
+
(0, chai_1.expect)(await client.zscore(RedisKey, "test-reschedule:renewal")).to.equal(String(later));
|
|
45
|
+
await cleanupRedis();
|
|
46
|
+
});
|
|
47
|
+
it("should keep due tasks when reading them fails", async () => {
|
|
48
|
+
await cleanupRedis();
|
|
49
|
+
const results = [];
|
|
50
|
+
(0, index_1.setHandler)("test-read-failure", (taskInfo) => {
|
|
51
|
+
results.push(taskInfo);
|
|
52
|
+
});
|
|
53
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
54
|
+
const due = Date.now() - 1000;
|
|
55
|
+
await client.zadd(RedisKey, due, "test-read-failure:renewal");
|
|
56
|
+
if (!isMockClient(client))
|
|
57
|
+
throw new Error("The test project must use the Redis mock");
|
|
58
|
+
const mock = client;
|
|
59
|
+
const store = mock.data;
|
|
60
|
+
let failed = false;
|
|
61
|
+
const failFirstRead = (key) => {
|
|
62
|
+
if (!failed && key === RedisKey) {
|
|
63
|
+
failed = true;
|
|
64
|
+
throw new Error("ERR injected read failure");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
mock.data = {
|
|
68
|
+
...store,
|
|
69
|
+
get: (key) => (failFirstRead(key), store.get(key)),
|
|
70
|
+
has: (key) => (failFirstRead(key), store.has(key)),
|
|
71
|
+
};
|
|
72
|
+
let rejected = false;
|
|
73
|
+
try {
|
|
74
|
+
await (0, index_1.runTasks)();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
rejected = true;
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
mock.data = store;
|
|
81
|
+
}
|
|
82
|
+
(0, chai_1.expect)(failed).to.equal(true);
|
|
83
|
+
(0, chai_1.expect)(rejected).to.equal(true);
|
|
84
|
+
(0, chai_1.expect)(results).to.deep.equal([]);
|
|
85
|
+
(0, chai_1.expect)(await client.zscore(RedisKey, "test-read-failure:renewal")).to.equal(String(due));
|
|
86
|
+
await cleanupRedis();
|
|
87
|
+
});
|
|
30
88
|
});
|
|
89
|
+
function isMockClient(client) {
|
|
90
|
+
return "data" in client;
|
|
91
|
+
}
|
|
31
92
|
describe("Redis Scheduler - retry logic", () => {
|
|
32
93
|
it("should retry failed tasks up to 3 times", async () => RetryFailedTasksTest());
|
|
33
94
|
});
|
|
34
95
|
async function RegisterHandlerTest() {
|
|
35
96
|
let called = false;
|
|
36
|
-
(0,
|
|
97
|
+
(0, index_1.setHandler)("test-register", () => {
|
|
37
98
|
called = true;
|
|
38
99
|
});
|
|
39
100
|
(0, chai_1.expect)(called).to.equal(false);
|
|
40
101
|
}
|
|
41
102
|
async function RejectColonInNameTest() {
|
|
42
103
|
try {
|
|
43
|
-
(0,
|
|
104
|
+
(0, index_1.setHandler)("invalid:name", () => { });
|
|
44
105
|
chai_1.expect.fail("should have thrown");
|
|
45
106
|
}
|
|
46
107
|
catch (err) {
|
|
@@ -49,9 +110,9 @@ async function RejectColonInNameTest() {
|
|
|
49
110
|
}
|
|
50
111
|
async function AddTaskTest() {
|
|
51
112
|
await cleanupRedis();
|
|
52
|
-
(0,
|
|
113
|
+
(0, index_1.setHandler)("test-add", () => { });
|
|
53
114
|
const dueTime = Date.now() + 60000;
|
|
54
|
-
await (0,
|
|
115
|
+
await (0, index_1.addTask)("test-add", dueTime, "task-data");
|
|
55
116
|
const client = await (0, interface_redis_1.GetClient)();
|
|
56
117
|
const members = await client.zrange(RedisKey, 0, -1);
|
|
57
118
|
(0, chai_1.expect)(members).to.include("test-add:task-data");
|
|
@@ -59,7 +120,7 @@ async function AddTaskTest() {
|
|
|
59
120
|
}
|
|
60
121
|
async function AddTaskUnknownHandlerTest() {
|
|
61
122
|
try {
|
|
62
|
-
await (0,
|
|
123
|
+
await (0, index_1.addTask)("nonexistent-handler", Date.now(), "data");
|
|
63
124
|
chai_1.expect.fail("should have thrown");
|
|
64
125
|
}
|
|
65
126
|
catch (err) {
|
|
@@ -68,17 +129,17 @@ async function AddTaskUnknownHandlerTest() {
|
|
|
68
129
|
}
|
|
69
130
|
async function RemoveTaskTest() {
|
|
70
131
|
await cleanupRedis();
|
|
71
|
-
(0,
|
|
132
|
+
(0, index_1.setHandler)("test-remove", () => { });
|
|
72
133
|
const client = await (0, interface_redis_1.GetClient)();
|
|
73
134
|
await client.zadd(RedisKey, Date.now() + 60000, "test-remove:remove-data");
|
|
74
|
-
await (0,
|
|
135
|
+
await (0, index_1.removeTask)("test-remove", "remove-data");
|
|
75
136
|
const members = await client.zrange(RedisKey, 0, -1);
|
|
76
137
|
(0, chai_1.expect)(members).to.not.include("test-remove:remove-data");
|
|
77
138
|
await cleanupRedis();
|
|
78
139
|
}
|
|
79
140
|
async function RemoveTaskUnknownHandlerTest() {
|
|
80
141
|
try {
|
|
81
|
-
await (0,
|
|
142
|
+
await (0, index_1.removeTask)("nonexistent-handler", "data");
|
|
82
143
|
chai_1.expect.fail("should have thrown");
|
|
83
144
|
}
|
|
84
145
|
catch (err) {
|
|
@@ -86,8 +147,8 @@ async function RemoveTaskUnknownHandlerTest() {
|
|
|
86
147
|
}
|
|
87
148
|
}
|
|
88
149
|
async function EnableDisableListenerTest() {
|
|
89
|
-
await (0,
|
|
90
|
-
await (0,
|
|
150
|
+
await (0, index_1.enableListener)();
|
|
151
|
+
await (0, index_1.disableListener)();
|
|
91
152
|
}
|
|
92
153
|
async function EnableListenerUsesLazyConnectTest() {
|
|
93
154
|
const client = await (0, interface_redis_1.GetClient)();
|
|
@@ -97,21 +158,21 @@ async function EnableListenerUsesLazyConnectTest() {
|
|
|
97
158
|
duplicateOptions = override;
|
|
98
159
|
return originalDuplicate(override);
|
|
99
160
|
});
|
|
100
|
-
await (0,
|
|
161
|
+
await (0, index_1.enableListener)();
|
|
101
162
|
(0, chai_1.expect)(duplicateOptions).to.deep.include({ lazyConnect: true });
|
|
102
|
-
await (0,
|
|
163
|
+
await (0, index_1.disableListener)();
|
|
103
164
|
client.duplicate = originalDuplicate;
|
|
104
165
|
}
|
|
105
166
|
async function RunDueTasksTest() {
|
|
106
167
|
await cleanupRedis();
|
|
107
168
|
const results = [];
|
|
108
|
-
(0,
|
|
169
|
+
(0, index_1.setHandler)("test-run", (taskInfo) => {
|
|
109
170
|
results.push(taskInfo);
|
|
110
171
|
});
|
|
111
172
|
const client = await (0, interface_redis_1.GetClient)();
|
|
112
173
|
await client.zadd(RedisKey, Date.now() - 1000, "test-run:payload1");
|
|
113
174
|
await client.zadd(RedisKey, Date.now() - 500, "test-run:payload2");
|
|
114
|
-
await (0,
|
|
175
|
+
await (0, index_1.runTasks)();
|
|
115
176
|
(0, chai_1.expect)(results).to.include("payload1");
|
|
116
177
|
(0, chai_1.expect)(results).to.include("payload2");
|
|
117
178
|
const remaining = await client.zrange(RedisKey, 0, -1);
|
|
@@ -121,12 +182,12 @@ async function RunDueTasksTest() {
|
|
|
121
182
|
async function SkipFutureTasksTest() {
|
|
122
183
|
await cleanupRedis();
|
|
123
184
|
const results = [];
|
|
124
|
-
(0,
|
|
185
|
+
(0, index_1.setHandler)("test-future", (taskInfo) => {
|
|
125
186
|
results.push(taskInfo);
|
|
126
187
|
});
|
|
127
188
|
const client = await (0, interface_redis_1.GetClient)();
|
|
128
189
|
await client.zadd(RedisKey, Date.now() + 60000, "test-future:future-data");
|
|
129
|
-
await (0,
|
|
190
|
+
await (0, index_1.runTasks)();
|
|
130
191
|
(0, chai_1.expect)(results).to.have.length(0);
|
|
131
192
|
const remaining = await client.zrange(RedisKey, 0, -1);
|
|
132
193
|
(0, chai_1.expect)(remaining).to.have.length(1);
|
|
@@ -135,13 +196,13 @@ async function SkipFutureTasksTest() {
|
|
|
135
196
|
async function RetryFailedTasksTest() {
|
|
136
197
|
await cleanupRedis();
|
|
137
198
|
let callCount = 0;
|
|
138
|
-
(0,
|
|
199
|
+
(0, index_1.setHandler)("test-retry", () => {
|
|
139
200
|
callCount++;
|
|
140
201
|
throw new Error("intentional failure");
|
|
141
202
|
});
|
|
142
203
|
const client = await (0, interface_redis_1.GetClient)();
|
|
143
204
|
await client.zadd(RedisKey, Date.now() - 1000, "test-retry:retry-data");
|
|
144
|
-
await (0,
|
|
205
|
+
await (0, index_1.runTasks)();
|
|
145
206
|
(0, chai_1.expect)(callCount).to.equal(1);
|
|
146
207
|
const retryMembers = await client.zrange(RedisKey, 0, -1);
|
|
147
208
|
(0, chai_1.expect)(retryMembers).to.have.length(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":";;AAAA,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,2BAA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,CAAC,CAAC,CAAC,CAAC;IAC1D,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACvC,IAAA,aAAM,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAEpE,MAAM,YAAY,EAAE,CAAC;AACvB,CAAC"}
|
package/docs/1.introduction.md
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
Interface Redis Scheduler
|
|
5
|
+
Interface Redis Scheduler stores tasks in a Redis sorted set with their due timestamps as scores. A local timer checks for due tasks, and Redis pub/sub notifies listeners when the schedule changes. Handlers that throw are retried, but the current implementation does not provide exactly-once delivery or an atomic claim across listeners.
|
|
6
|
+
|
|
7
|
+
Use one active listener for a queue and make handlers idempotent. Concurrent listeners can read the same due tasks before either removes them, and a process failure after removal but before handler completion can lose a task. Redis persistence protects queued entries only according to the server's persistence configuration.
|
|
8
|
+
|
|
9
|
+
## Schedule a task safely
|
|
10
|
+
|
|
11
|
+
1. Register the task type with [`setHandler`](#sethandler), including in processes that enqueue or remove tasks.
|
|
12
|
+
2. Start one active [`enableListener`](#enablelistener) for the queue after registering its handlers.
|
|
13
|
+
3. Save the serialized payload, then call [`addTask`](#addtask) with a due time in milliseconds.
|
|
14
|
+
4. Use that exact payload for [`removeTask`](#removetask); do not recreate timestamps when canceling.
|
|
15
|
+
|
|
16
|
+
{width="480"}
|
|
17
|
+
|
|
18
|
+
**Decide before adopting:** this scheduler fits work whose loss or repetition your application can tolerate or reconcile. It does not promise exactly-once execution, durable in-flight ownership, or a full shutdown/drain API. Review [retry logic](#retry-logic) and [shutdown limits](#disablelistener) before production use.
|
|
6
19
|
|
|
7
20
|
## Getting Started
|
|
8
21
|
|
|
@@ -14,6 +27,36 @@ npm install @antelopejs/interface-redis-scheduler
|
|
|
14
27
|
|
|
15
28
|
> **Note:** This package depends on `@antelopejs/interface-redis`. You must have it installed and configured for the scheduler to connect to Redis.
|
|
16
29
|
|
|
30
|
+
## Try one scheduled task
|
|
31
|
+
|
|
32
|
+
Run this from an initialized application against a disposable Redis database,
|
|
33
|
+
with no other scheduler listener. It logs a reminder after about one minute;
|
|
34
|
+
it does not send an email or charge a payment.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import {
|
|
38
|
+
setHandler,
|
|
39
|
+
enableListener,
|
|
40
|
+
addTask,
|
|
41
|
+
} from "@antelopejs/interface-redis-scheduler";
|
|
42
|
+
|
|
43
|
+
setHandler("docs-reminder", (taskInfo) => {
|
|
44
|
+
console.log("Reminder:", taskInfo);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
await enableListener();
|
|
48
|
+
const taskInfo = JSON.stringify({
|
|
49
|
+
jobId: "demo-001",
|
|
50
|
+
message: "Review your draft",
|
|
51
|
+
});
|
|
52
|
+
await addTask("docs-reminder", Date.now() + 60_000, taskInfo);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Keep the process alive to observe the reminder. The due time is a Unix timestamp
|
|
56
|
+
in milliseconds, not a delay. Save `taskInfo` if you may later remove the queued
|
|
57
|
+
entry; [removal is not a cancellation guarantee](#removetask). The public API does
|
|
58
|
+
not fully stop timers, so end this disposable process when finished.
|
|
59
|
+
|
|
17
60
|
## Core Concepts
|
|
18
61
|
|
|
19
62
|
The scheduler operates around three main ideas:
|
|
@@ -24,7 +67,7 @@ The scheduler operates around three main ideas:
|
|
|
24
67
|
|
|
25
68
|
## `setHandler`
|
|
26
69
|
|
|
27
|
-
The `setHandler` function registers a handler for a specific task type. Each handler has a unique name and a callback function that receives the task data as a string.
|
|
70
|
+
The `setHandler` function registers a handler for a specific task type. Each handler has a unique name and a callback function that receives the task data as a string. The `sendEmail` function below belongs to your application; it is not a scheduler export.
|
|
28
71
|
|
|
29
72
|
```typescript
|
|
30
73
|
import { setHandler } from "@antelopejs/interface-redis-scheduler";
|
|
@@ -43,9 +86,9 @@ Handler names must not contain the `:` character, as the scheduler uses it inter
|
|
|
43
86
|
|
|
44
87
|
### Parameters
|
|
45
88
|
|
|
46
|
-
| Parameter | Type
|
|
47
|
-
| ------------- |
|
|
48
|
-
| `handlerName` | `string`
|
|
89
|
+
| Parameter | Type | Description |
|
|
90
|
+
| ------------- | --------------------------------------------- | ----------------------------------- |
|
|
91
|
+
| `handlerName` | `string` | Unique identifier for the task type |
|
|
49
92
|
| `handler` | `(taskInfo: string) => void \| Promise<void>` | Function that processes the task |
|
|
50
93
|
|
|
51
94
|
## `enableListener`
|
|
@@ -69,14 +112,16 @@ async function startApp() {
|
|
|
69
112
|
|
|
70
113
|
## `disableListener`
|
|
71
114
|
|
|
72
|
-
|
|
115
|
+
`disableListener()` returns `Promise<void>` and only calls `quit()` on the notification subscriber. Call it only after `enableListener()` has completed successfully.
|
|
116
|
+
|
|
117
|
+
> **Warning:** It does not clear the pending timer, cancel running handlers, or wait for task completion. An already scheduled timer can still execute tasks and schedule another timer through `updateTimer()`. Do not use this function as a pause, a drain, or a guarantee that no more tasks run. The current public API has no complete timer shutdown operation.
|
|
73
118
|
|
|
74
119
|
```typescript
|
|
75
120
|
import { disableListener } from "@antelopejs/interface-redis-scheduler";
|
|
76
121
|
|
|
77
122
|
async function stopApp() {
|
|
78
123
|
await disableListener();
|
|
79
|
-
console.log("
|
|
124
|
+
console.log("Notification subscriber closed; task processing may continue");
|
|
80
125
|
}
|
|
81
126
|
```
|
|
82
127
|
|
|
@@ -87,22 +132,26 @@ The `addTask` function schedules a task for execution at a specific time. The ta
|
|
|
87
132
|
```typescript
|
|
88
133
|
import { addTask } from "@antelopejs/interface-redis-scheduler";
|
|
89
134
|
|
|
90
|
-
async function scheduleReminder(
|
|
135
|
+
async function scheduleReminder(recipient: string) {
|
|
91
136
|
// Schedule for 3 days from now
|
|
92
137
|
const dueTime = Date.now() + 3 * 24 * 60 * 60 * 1000;
|
|
93
138
|
|
|
94
139
|
const taskInfo = JSON.stringify({
|
|
95
|
-
|
|
96
|
-
|
|
140
|
+
recipient,
|
|
141
|
+
subject: "Review your draft",
|
|
142
|
+
body: "Your draft is waiting for review.",
|
|
97
143
|
createdAt: new Date().toISOString(),
|
|
98
144
|
});
|
|
99
145
|
|
|
100
146
|
await addTask("send-email", dueTime, taskInfo);
|
|
147
|
+
return taskInfo; // Persist this exact string for removal.
|
|
101
148
|
}
|
|
102
149
|
```
|
|
103
150
|
|
|
104
151
|
The function throws an error if the specified handler name has not been registered.
|
|
105
152
|
|
|
153
|
+
The pair `handlerName` + `taskInfo` identifies the queued member. Adding the same pair again changes its due time rather than creating another independent task. Include a stable job ID in the payload when two otherwise identical jobs must remain distinct.
|
|
154
|
+
|
|
106
155
|
### Parameters
|
|
107
156
|
|
|
108
157
|
| Parameter | Type | Description |
|
|
@@ -113,19 +162,13 @@ The function throws an error if the specified handler name has not been register
|
|
|
113
162
|
|
|
114
163
|
## `removeTask`
|
|
115
164
|
|
|
116
|
-
The `removeTask` function
|
|
165
|
+
The `removeTask` function removes the original queued entry, if it is still present. Pass the saved `taskInfo` string returned by `scheduleReminder`, rather than reconstructing the JSON.
|
|
117
166
|
|
|
118
167
|
```typescript
|
|
119
168
|
import { removeTask } from "@antelopejs/interface-redis-scheduler";
|
|
120
169
|
|
|
121
|
-
async function
|
|
122
|
-
|
|
123
|
-
userId,
|
|
124
|
-
type: "password_reminder",
|
|
125
|
-
createdAt: "2025-04-05T12:00:00.000Z", // Must match exactly
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
await removeTask("send-email", taskInfo);
|
|
170
|
+
async function removeQueuedReminder(savedTaskInfo: string) {
|
|
171
|
+
await removeTask("send-email", savedTaskInfo);
|
|
129
172
|
}
|
|
130
173
|
```
|
|
131
174
|
|
|
@@ -133,20 +176,22 @@ The function throws an error if the specified handler name has not been register
|
|
|
133
176
|
|
|
134
177
|
> **Warning:** The `taskInfo` must be an exact string match of the original task. If the serialized JSON differs in key order or whitespace, the removal fails silently.
|
|
135
178
|
|
|
179
|
+
Removal targets the original queued member only. It does not stop a running handler or remove a retry stored with a `RETRY-` prefix. If cancellation must survive races and retries, make the handler check application-owned cancellation state before applying effects.
|
|
180
|
+
|
|
136
181
|
### Parameters
|
|
137
182
|
|
|
138
|
-
| Parameter | Type | Description
|
|
139
|
-
| ------------- | -------- |
|
|
140
|
-
| `handlerName` | `string` | The handler name associated with the task
|
|
183
|
+
| Parameter | Type | Description |
|
|
184
|
+
| ------------- | -------- | ---------------------------------------------------- |
|
|
185
|
+
| `handlerName` | `string` | The handler name associated with the task |
|
|
141
186
|
| `taskInfo` | `string` | The exact task info string used when adding the task |
|
|
142
187
|
|
|
143
188
|
## Retry Logic
|
|
144
189
|
|
|
145
190
|
The scheduler automatically retries failed tasks. When a handler throws an error, the scheduler reschedules the task with a retry counter.
|
|
146
191
|
|
|
147
|
-
- **Maximum retries:** 3 attempts
|
|
192
|
+
- **Maximum retries:** 3 retries after the initial attempt (4 attempts total)
|
|
148
193
|
- **Retry delay:** 5 seconds between each attempt
|
|
149
|
-
- **Behavior on exhaustion:** After 3 failed retries, the task is discarded
|
|
194
|
+
- **Behavior on exhaustion:** After 3 failed retries, the task is discarded; failures are reported through `Logging.Error`
|
|
150
195
|
|
|
151
196
|
No additional code is required to enable retries. The mechanism is built into the task execution loop.
|
|
152
197
|
|
|
@@ -154,20 +199,24 @@ No additional code is required to enable retries. The mechanism is built into th
|
|
|
154
199
|
import { setHandler } from "@antelopejs/interface-redis-scheduler";
|
|
155
200
|
|
|
156
201
|
// If this handler throws, the scheduler retries up to 3 times
|
|
157
|
-
setHandler("
|
|
202
|
+
setHandler("refresh-summary", async (taskInfo) => {
|
|
158
203
|
const data = JSON.parse(taskInfo);
|
|
159
|
-
await
|
|
204
|
+
await refreshSummary(data);
|
|
160
205
|
// On failure: retry after 5s, then 5s, then 5s, then discard
|
|
161
206
|
});
|
|
162
207
|
```
|
|
163
208
|
|
|
209
|
+
`refreshSummary` is an application function that recomputes a replaceable summary.
|
|
210
|
+
Choose retryable, idempotent work; a retry is not proof that the previous attempt
|
|
211
|
+
had no effect. Do not use this sketch as a durable payment-processing queue.
|
|
212
|
+
|
|
164
213
|
## Redis Storage
|
|
165
214
|
|
|
166
215
|
The scheduler uses a single Redis sorted set with the key `SchedulerUtil.Tasks`. Each member in the sorted set follows the format `handlerName:taskInfo`, and its score is the due timestamp in milliseconds.
|
|
167
216
|
|
|
168
217
|
For retried tasks, the format becomes `RETRY-{count}:handlerName:taskInfo`, where `{count}` tracks the number of retry attempts.
|
|
169
218
|
|
|
170
|
-
The scheduler also uses a Redis pub/sub channel named `SchedulerUtil` to notify listener instances when new tasks are added
|
|
219
|
+
The scheduler also uses a Redis pub/sub channel named `SchedulerUtil` to notify listener instances when new tasks are added. These notifications refresh timers; they do not lock or atomically claim tasks across processes.
|
|
171
220
|
|
|
172
221
|
## `updateTimer`
|
|
173
222
|
|
|
@@ -193,7 +242,7 @@ await runTasks();
|
|
|
193
242
|
|
|
194
243
|
## Complete Example
|
|
195
244
|
|
|
196
|
-
|
|
245
|
+
This integration sketch shows handler registration, listener startup, scheduling, and subscriber cleanup. `sendEmail`, `deleteSession`, and `refreshSummary` in these examples stand for application functions you supply; they are not scheduler exports. The examples require a configured Redis implementation and do not run a service from this page.
|
|
197
246
|
|
|
198
247
|
```typescript
|
|
199
248
|
import {
|
|
@@ -227,21 +276,21 @@ async function onUserSignup(userId: string, email: string) {
|
|
|
227
276
|
await addTask(
|
|
228
277
|
"send-email",
|
|
229
278
|
dueTime,
|
|
230
|
-
JSON.stringify({
|
|
279
|
+
JSON.stringify({
|
|
280
|
+
to: email,
|
|
281
|
+
subject: "Welcome!",
|
|
282
|
+
body: "Thanks for signing up.",
|
|
283
|
+
}),
|
|
231
284
|
);
|
|
232
285
|
}
|
|
233
286
|
|
|
234
287
|
async function onUserLogout(sessionId: string) {
|
|
235
288
|
// Clean up session data in 24 hours
|
|
236
289
|
const dueTime = Date.now() + 24 * 60 * 60 * 1000;
|
|
237
|
-
await addTask(
|
|
238
|
-
"cleanup-session",
|
|
239
|
-
dueTime,
|
|
240
|
-
JSON.stringify({ sessionId }),
|
|
241
|
-
);
|
|
290
|
+
await addTask("cleanup-session", dueTime, JSON.stringify({ sessionId }));
|
|
242
291
|
}
|
|
243
292
|
|
|
244
|
-
// 4.
|
|
293
|
+
// 4. Close notifications on shutdown (pending timers and handlers may continue)
|
|
245
294
|
async function shutdown() {
|
|
246
295
|
await disableListener();
|
|
247
296
|
}
|
|
@@ -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 due tasks from a sorted set and removes them 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">One listener · idempotent handlers</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">Not an atomic claim</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,26 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-redis-scheduler",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "AntelopeJS interface for Redis
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"description": "AntelopeJS interface for scheduling tasks on Redis, with retries on failure",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
7
7
|
"interface",
|
|
8
8
|
"redis",
|
|
9
|
-
"scheduler"
|
|
9
|
+
"scheduler",
|
|
10
|
+
"tasks"
|
|
10
11
|
],
|
|
12
|
+
"homepage": "https://interfaces.antelopejs.com/docs/redis-scheduler",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/AntelopeJS/interface-redis-scheduler/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "Apache-2.0",
|
|
11
17
|
"repository": {
|
|
12
18
|
"type": "git",
|
|
13
19
|
"url": "git+https://github.com/AntelopeJS/interface-redis-scheduler.git"
|
|
14
20
|
},
|
|
15
|
-
"license": "Apache-2.0",
|
|
16
|
-
"packageManager": "pnpm@10.6.5",
|
|
17
|
-
"main": "dist/index.js",
|
|
18
|
-
"types": "dist/index.d.ts",
|
|
19
21
|
"files": [
|
|
20
22
|
"dist",
|
|
21
23
|
"docs",
|
|
22
24
|
"skills"
|
|
23
25
|
],
|
|
26
|
+
"main": "dist/index.js",
|
|
27
|
+
"types": "dist/index.d.ts",
|
|
24
28
|
"exports": {
|
|
25
29
|
".": {
|
|
26
30
|
"types": "./dist/index.d.ts",
|
|
@@ -28,38 +32,57 @@
|
|
|
28
32
|
},
|
|
29
33
|
"./package.json": "./package.json"
|
|
30
34
|
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"provenance": true
|
|
38
|
+
},
|
|
31
39
|
"scripts": {
|
|
32
40
|
"build": "rimraf dist && tsc",
|
|
33
|
-
"format": "
|
|
34
|
-
"lint:fix": "
|
|
35
|
-
"lint": "
|
|
41
|
+
"format": "oxfmt .",
|
|
42
|
+
"lint:fix": "oxlint --fix",
|
|
43
|
+
"lint": "oxlint",
|
|
36
44
|
"prepack": "pnpm run build",
|
|
37
45
|
"release": "pnpm run lint && pnpm run prepack && release-it",
|
|
38
|
-
"test": "pnpm run build && ajs module test ."
|
|
46
|
+
"test": "pnpm run build && ajs module test .",
|
|
47
|
+
"format:check": "oxfmt --check .",
|
|
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
|
+
"ratchet": "antelopejs-ratchet",
|
|
53
|
+
"sync": "antelopejs-sync",
|
|
54
|
+
"ratchet:update": "antelopejs-ratchet --update",
|
|
55
|
+
"sync:check": "antelopejs-sync --check",
|
|
56
|
+
"typecheck": "tsc --noEmit"
|
|
39
57
|
},
|
|
40
58
|
"dependencies": {
|
|
41
59
|
"ioredis": "^5.10.1"
|
|
42
60
|
},
|
|
43
61
|
"devDependencies": {
|
|
44
|
-
"@antelopejs/
|
|
45
|
-
"@antelopejs/interface-
|
|
46
|
-
"@
|
|
62
|
+
"@antelopejs/core": "^1.16.0",
|
|
63
|
+
"@antelopejs/interface-core": "^0.2.4",
|
|
64
|
+
"@antelopejs/interface-redis": "^0.0.9",
|
|
65
|
+
"@antelopejs/tooling-configs": "^0.2.0",
|
|
47
66
|
"@types/chai": "^4.3.20",
|
|
48
67
|
"@types/mocha": "^10.0.10",
|
|
49
68
|
"@types/node": "^22.19.15",
|
|
50
69
|
"chai": "^4.5.0",
|
|
70
|
+
"eslint-plugin-perfectionist": "^5.11.0",
|
|
71
|
+
"knip": "^6.34.0",
|
|
72
|
+
"lefthook": "^2.2.2",
|
|
73
|
+
"oxfmt": "^0.66.0",
|
|
74
|
+
"oxlint": "1.81.0",
|
|
75
|
+
"oxlint-tsgolint": "^7.0.2001",
|
|
51
76
|
"release-it": "^19.2.4",
|
|
52
77
|
"release-it-changelogen": "^0.1.0",
|
|
53
78
|
"rimraf": "^6.1.3",
|
|
54
79
|
"typescript": "^5.9.3"
|
|
55
80
|
},
|
|
56
81
|
"peerDependencies": {
|
|
57
|
-
"@antelopejs/interface-core": ">=0.
|
|
58
|
-
"@antelopejs/interface-redis": ">=0.0.
|
|
59
|
-
},
|
|
60
|
-
"publishConfig": {
|
|
61
|
-
"access": "public"
|
|
82
|
+
"@antelopejs/interface-core": ">=0.2.4 <1.0.0",
|
|
83
|
+
"@antelopejs/interface-redis": ">=0.0.9 <1.0.0"
|
|
62
84
|
},
|
|
85
|
+
"packageManager": "pnpm@10.6.5",
|
|
63
86
|
"antelopeJs": {
|
|
64
87
|
"test": "src/antelope.test.ts",
|
|
65
88
|
"skills": [
|