@antelopejs/interface-redis-scheduler 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +38 -0
- package/dist/antelope.test.d.ts +2 -0
- package/dist/antelope.test.js +21 -0
- package/dist/antelope.test.js.map +1 -0
- package/dist/index.d.ts +129 -0
- package/dist/index.js +250 -0
- package/dist/index.js.map +1 -0
- package/dist/tests/index.test.d.ts +1 -0
- package/dist/tests/index.test.js +151 -0
- package/dist/tests/index.test.js.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright (c) 2025-present - AntelopeJS Team
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Interface Redis Scheduler
|
|
4
|
+
|
|
5
|
+
<div align="center">
|
|
6
|
+
<a href="./LICENSE"><img alt="License" src="https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=for-the-badge&labelColor=000000"></a>
|
|
7
|
+
<a href="https://discord.gg/sjK28QHrA7"><img src="https://img.shields.io/badge/Discord-18181B?logo=discord&style=for-the-badge&color=000000" alt="Discord"></a>
|
|
8
|
+
<a href="./docs/1.index.md"><img src="https://img.shields.io/badge/Docs-18181B?style=for-the-badge&color=000000" alt="Documentation"></a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
A robust task scheduling system built on top of Redis. Interface Redis Scheduler enables reliable, distributed scheduling of tasks across multiple application instances, with support for automatic retries and failure handling.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ajs module imports add redis_scheduler@beta
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Documentation
|
|
20
|
+
|
|
21
|
+
Detailed documentation is available in the `docs` directory:
|
|
22
|
+
|
|
23
|
+
- [Index](./docs/1.index.md) - Core functionality and usage examples
|
|
24
|
+
|
|
25
|
+
## Current Status
|
|
26
|
+
|
|
27
|
+
This is the development version (`beta`) of the Interface Redis Scheduler. It is currently in pre-release stage and may undergo changes before the final release. The interface is not considered stable for production use without understanding that breaking changes may occur.
|
|
28
|
+
|
|
29
|
+
## Versions
|
|
30
|
+
|
|
31
|
+
| Version | Link | Status |
|
|
32
|
+
| ------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
|
|
33
|
+
| beta | [redis_scheduler@beta](https://github.com/AntelopeJS/redis/tree/main/output/redis_scheduler/beta.d.ts) | Waiting validation from community to go in v1 |
|
|
34
|
+
| 1 | _Not yet released_ | Planned stable release |
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("@antelopejs/interface-core/config");
|
|
4
|
+
exports.default = (0, config_1.defineConfig)({
|
|
5
|
+
name: "interface-redis-scheduler-test",
|
|
6
|
+
cacheFolder: ".antelope/cache",
|
|
7
|
+
modules: {
|
|
8
|
+
redis: {
|
|
9
|
+
source: {
|
|
10
|
+
type: "local",
|
|
11
|
+
path: "../redis",
|
|
12
|
+
installCommand: ["pnpm install", "npx tsc"],
|
|
13
|
+
},
|
|
14
|
+
config: { useMock: true },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
test: {
|
|
18
|
+
folder: "dist/tests",
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=antelope.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"antelope.test.js","sourceRoot":"","sources":["../src/antelope.test.ts"],"names":[],"mappings":";;AAAA,8DAAiE;AAEjE,kBAAe,IAAA,qBAAY,EAAC;IAC1B,IAAI,EAAE,gCAAgC;IACtC,WAAW,EAAE,iBAAiB;IAC9B,OAAO,EAAE;QACP,KAAK,EAAE;YACL,MAAM,EAAE;gBACN,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,UAAU;gBAChB,cAAc,EAAE,CAAC,cAAc,EAAE,SAAS,CAAC;aAC5C;YACD,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SAC1B;KACF;IACD,IAAI,EAAE;QACJ,MAAM,EAAE,YAAY;KACrB;CACF,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler function type for processing scheduled tasks
|
|
3
|
+
* @param taskInfo - A string containing the task data, typically JSON-formatted
|
|
4
|
+
*/
|
|
5
|
+
type HandlerType = (taskInfo: string) => void | Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Registers a handler function for a specific task type
|
|
8
|
+
*
|
|
9
|
+
* @param handlerName - Unique identifier for the task type (must not contain ':')
|
|
10
|
+
* @param handler - Function that processes tasks of this type
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { setHandler } from '@antelopejs/interface-redis-scheduler';
|
|
15
|
+
*
|
|
16
|
+
* // Register a handler for email tasks
|
|
17
|
+
* setHandler('send-email', async (taskInfo) => {
|
|
18
|
+
* const emailData = JSON.parse(taskInfo);
|
|
19
|
+
* await sendEmail({
|
|
20
|
+
* to: emailData.recipient,
|
|
21
|
+
* subject: emailData.subject,
|
|
22
|
+
* body: emailData.body
|
|
23
|
+
* });
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function setHandler(handlerName: string, handler: HandlerType): void;
|
|
28
|
+
/**
|
|
29
|
+
* Enables the task execution listener
|
|
30
|
+
* This starts monitoring for scheduled tasks and executes them when due
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { enableListener } from '@antelopejs/interface-redis-scheduler';
|
|
35
|
+
*
|
|
36
|
+
* // During application startup
|
|
37
|
+
* async function startApp() {
|
|
38
|
+
* // Register task handlers
|
|
39
|
+
* // ...
|
|
40
|
+
*
|
|
41
|
+
* // Start the task listener
|
|
42
|
+
* await enableListener();
|
|
43
|
+
* console.log('Task scheduler is now active');
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function enableListener(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Disables the task execution listener
|
|
50
|
+
* This stops the scheduler from processing any further tasks
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { disableListener } from '@antelopejs/interface-redis-scheduler';
|
|
55
|
+
*
|
|
56
|
+
* // During application shutdown
|
|
57
|
+
* async function stopApp() {
|
|
58
|
+
* await disableListener();
|
|
59
|
+
* console.log('Task scheduler stopped');
|
|
60
|
+
* }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function disableListener(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Schedules a task to be executed at a specific time
|
|
66
|
+
*
|
|
67
|
+
* @param handlerName - The registered handler name that will process this task
|
|
68
|
+
* @param dueTime - Unix timestamp (milliseconds) when the task should be executed
|
|
69
|
+
* @param taskInfo - String containing any data needed by the handler (typically JSON)
|
|
70
|
+
* @throws Error if the handler name is not registered
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { addTask } from '@antelopejs/interface-redis-scheduler';
|
|
75
|
+
*
|
|
76
|
+
* // Schedule a task for future execution
|
|
77
|
+
* async function schedulePasswordReminder(userId: string) {
|
|
78
|
+
* // Schedule for 3 days from now
|
|
79
|
+
* const dueTime = Date.now() + 3 * 24 * 60 * 60 * 1000;
|
|
80
|
+
*
|
|
81
|
+
* const taskInfo = JSON.stringify({
|
|
82
|
+
* userId,
|
|
83
|
+
* type: 'password_reminder',
|
|
84
|
+
* createdAt: new Date().toISOString()
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* await addTask('send-email', dueTime, taskInfo);
|
|
88
|
+
* console.log(`Password reminder scheduled for user ${userId}`);
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function addTask(handlerName: string, dueTime: number, taskInfo: string): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Removes a previously scheduled task
|
|
95
|
+
*
|
|
96
|
+
* @param handlerName - The handler name associated with the task
|
|
97
|
+
* @param taskInfo - The exact task info string used when scheduling the task
|
|
98
|
+
* @throws Error if the handler name is not registered
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* import { removeTask } from '@antelopejs/interface-redis-scheduler';
|
|
103
|
+
*
|
|
104
|
+
* // Cancel a previously scheduled reminder
|
|
105
|
+
* async function cancelReminder(userId: string) {
|
|
106
|
+
* const taskInfo = JSON.stringify({
|
|
107
|
+
* userId,
|
|
108
|
+
* type: 'password_reminder',
|
|
109
|
+
* createdAt: '2023-04-05T12:00:00.000Z' // Must match exactly
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* await removeTask('send-email', taskInfo);
|
|
113
|
+
* console.log(`Reminder canceled for user ${userId}`);
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function removeTask(handlerName: string, taskInfo: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Updates the timer for the next task execution
|
|
120
|
+
* This is called internally whenever the task schedule changes
|
|
121
|
+
*/
|
|
122
|
+
export declare function updateTimer(): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Executes all due tasks
|
|
125
|
+
* This is called internally by the timer when tasks are due for execution
|
|
126
|
+
* It includes automatic retry logic for failed tasks
|
|
127
|
+
*/
|
|
128
|
+
export declare function runTasks(): Promise<void>;
|
|
129
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setHandler = setHandler;
|
|
4
|
+
exports.enableListener = enableListener;
|
|
5
|
+
exports.disableListener = disableListener;
|
|
6
|
+
exports.addTask = addTask;
|
|
7
|
+
exports.removeTask = removeTask;
|
|
8
|
+
exports.updateTimer = updateTimer;
|
|
9
|
+
exports.runTasks = runTasks;
|
|
10
|
+
const interface_core_1 = require("@antelopejs/interface-core");
|
|
11
|
+
const interface_redis_1 = require("@antelopejs/interface-redis");
|
|
12
|
+
/** Redis key used to store scheduled tasks in a sorted set */
|
|
13
|
+
const RedisKey = "SchedulerUtil.Tasks";
|
|
14
|
+
const SchedulerChannel = "SchedulerUtil";
|
|
15
|
+
const SchedulerUpdateMessage = "update";
|
|
16
|
+
const MaxRetries = 3;
|
|
17
|
+
const RetryDelayMs = 5000;
|
|
18
|
+
const MaxTimerDelayMs = 86400000;
|
|
19
|
+
const RetryPattern = /^(?:RETRY-(\d)+:)?([^:]*):(.*)$/;
|
|
20
|
+
/** Map of registered task handlers by name */
|
|
21
|
+
const handlers = new Map();
|
|
22
|
+
/** Proxy for registering/unregistering task handlers */
|
|
23
|
+
const proxy = new interface_core_1.RegisteringProxy();
|
|
24
|
+
proxy.onRegister((handlerName, handler) => {
|
|
25
|
+
if (handlerName.indexOf(":") !== -1) {
|
|
26
|
+
throw new Error("SchedulerUtil handler name may not contain `:`");
|
|
27
|
+
}
|
|
28
|
+
handlers.set(handlerName, handler);
|
|
29
|
+
}, true);
|
|
30
|
+
proxy.onUnregister((handlerName) => {
|
|
31
|
+
handlers.delete(handlerName);
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Registers a handler function for a specific task type
|
|
35
|
+
*
|
|
36
|
+
* @param handlerName - Unique identifier for the task type (must not contain ':')
|
|
37
|
+
* @param handler - Function that processes tasks of this type
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* import { setHandler } from '@antelopejs/interface-redis-scheduler';
|
|
42
|
+
*
|
|
43
|
+
* // Register a handler for email tasks
|
|
44
|
+
* setHandler('send-email', async (taskInfo) => {
|
|
45
|
+
* const emailData = JSON.parse(taskInfo);
|
|
46
|
+
* await sendEmail({
|
|
47
|
+
* to: emailData.recipient,
|
|
48
|
+
* subject: emailData.subject,
|
|
49
|
+
* body: emailData.body
|
|
50
|
+
* });
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function setHandler(handlerName, handler) {
|
|
55
|
+
proxy.register(handlerName, handler);
|
|
56
|
+
}
|
|
57
|
+
/** Redis subscriber client for receiving task updates */
|
|
58
|
+
let subscriber;
|
|
59
|
+
const SubscriberMessageHandlers = {
|
|
60
|
+
[SchedulerUpdateMessage]: () => void updateTimer(),
|
|
61
|
+
};
|
|
62
|
+
function createTaskMember(handlerName, taskInfo) {
|
|
63
|
+
return `${handlerName}:${taskInfo}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Enables the task execution listener
|
|
67
|
+
* This starts monitoring for scheduled tasks and executes them when due
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* import { enableListener } from '@antelopejs/interface-redis-scheduler';
|
|
72
|
+
*
|
|
73
|
+
* // During application startup
|
|
74
|
+
* async function startApp() {
|
|
75
|
+
* // Register task handlers
|
|
76
|
+
* // ...
|
|
77
|
+
*
|
|
78
|
+
* // Start the task listener
|
|
79
|
+
* await enableListener();
|
|
80
|
+
* console.log('Task scheduler is now active');
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async function enableListener() {
|
|
85
|
+
subscriber = (await (0, interface_redis_1.GetClient)()).duplicate({ lazyConnect: true });
|
|
86
|
+
await subscriber.connect();
|
|
87
|
+
await subscriber.subscribe(SchedulerChannel);
|
|
88
|
+
subscriber.on("message", (channel, message) => {
|
|
89
|
+
if (channel !== SchedulerChannel) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const handler = SubscriberMessageHandlers[message];
|
|
93
|
+
if (!handler) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
handler();
|
|
97
|
+
});
|
|
98
|
+
void updateTimer();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Disables the task execution listener
|
|
102
|
+
* This stops the scheduler from processing any further tasks
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* import { disableListener } from '@antelopejs/interface-redis-scheduler';
|
|
107
|
+
*
|
|
108
|
+
* // During application shutdown
|
|
109
|
+
* async function stopApp() {
|
|
110
|
+
* await disableListener();
|
|
111
|
+
* console.log('Task scheduler stopped');
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
async function disableListener() {
|
|
116
|
+
await subscriber.quit();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Schedules a task to be executed at a specific time
|
|
120
|
+
*
|
|
121
|
+
* @param handlerName - The registered handler name that will process this task
|
|
122
|
+
* @param dueTime - Unix timestamp (milliseconds) when the task should be executed
|
|
123
|
+
* @param taskInfo - String containing any data needed by the handler (typically JSON)
|
|
124
|
+
* @throws Error if the handler name is not registered
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* import { addTask } from '@antelopejs/interface-redis-scheduler';
|
|
129
|
+
*
|
|
130
|
+
* // Schedule a task for future execution
|
|
131
|
+
* async function schedulePasswordReminder(userId: string) {
|
|
132
|
+
* // Schedule for 3 days from now
|
|
133
|
+
* const dueTime = Date.now() + 3 * 24 * 60 * 60 * 1000;
|
|
134
|
+
*
|
|
135
|
+
* const taskInfo = JSON.stringify({
|
|
136
|
+
* userId,
|
|
137
|
+
* type: 'password_reminder',
|
|
138
|
+
* createdAt: new Date().toISOString()
|
|
139
|
+
* });
|
|
140
|
+
*
|
|
141
|
+
* await addTask('send-email', dueTime, taskInfo);
|
|
142
|
+
* console.log(`Password reminder scheduled for user ${userId}`);
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
async function addTask(handlerName, dueTime, taskInfo) {
|
|
147
|
+
if (!handlers.has(handlerName)) {
|
|
148
|
+
throw new Error(`Unknown SchedulerUtil handler: ${handlerName}`);
|
|
149
|
+
}
|
|
150
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
151
|
+
await client.zadd(RedisKey, dueTime, createTaskMember(handlerName, taskInfo));
|
|
152
|
+
if (!locked) {
|
|
153
|
+
void client.publish(SchedulerChannel, SchedulerUpdateMessage);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Removes a previously scheduled task
|
|
158
|
+
*
|
|
159
|
+
* @param handlerName - The handler name associated with the task
|
|
160
|
+
* @param taskInfo - The exact task info string used when scheduling the task
|
|
161
|
+
* @throws Error if the handler name is not registered
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import { removeTask } from '@antelopejs/interface-redis-scheduler';
|
|
166
|
+
*
|
|
167
|
+
* // Cancel a previously scheduled reminder
|
|
168
|
+
* async function cancelReminder(userId: string) {
|
|
169
|
+
* const taskInfo = JSON.stringify({
|
|
170
|
+
* userId,
|
|
171
|
+
* type: 'password_reminder',
|
|
172
|
+
* createdAt: '2023-04-05T12:00:00.000Z' // Must match exactly
|
|
173
|
+
* });
|
|
174
|
+
*
|
|
175
|
+
* await removeTask('send-email', taskInfo);
|
|
176
|
+
* console.log(`Reminder canceled for user ${userId}`);
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
async function removeTask(handlerName, taskInfo) {
|
|
181
|
+
if (!handlers.has(handlerName)) {
|
|
182
|
+
throw new Error(`Unknown SchedulerUtil handler: ${handlerName}`);
|
|
183
|
+
}
|
|
184
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
185
|
+
await client.zrem(RedisKey, createTaskMember(handlerName, taskInfo));
|
|
186
|
+
}
|
|
187
|
+
/** Flag to prevent concurrent task execution */
|
|
188
|
+
let locked = false;
|
|
189
|
+
/** Timer for scheduling the next task check */
|
|
190
|
+
let timer;
|
|
191
|
+
/**
|
|
192
|
+
* Updates the timer for the next task execution
|
|
193
|
+
* This is called internally whenever the task schedule changes
|
|
194
|
+
*/
|
|
195
|
+
async function updateTimer() {
|
|
196
|
+
if (locked) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
200
|
+
const taskInfo = (await client.zrange(RedisKey, 0, 0))[0];
|
|
201
|
+
if (taskInfo) {
|
|
202
|
+
const scoreValue = await client.zscore(RedisKey, taskInfo);
|
|
203
|
+
if (!scoreValue) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const score = Number(scoreValue);
|
|
207
|
+
if (score < Date.now()) {
|
|
208
|
+
await runTasks();
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
if (timer) {
|
|
212
|
+
clearTimeout(timer);
|
|
213
|
+
}
|
|
214
|
+
timer = setTimeout(() => void runTasks(), Math.min(score - Date.now(), MaxTimerDelayMs));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Executes all due tasks
|
|
220
|
+
* This is called internally by the timer when tasks are due for execution
|
|
221
|
+
* It includes automatic retry logic for failed tasks
|
|
222
|
+
*/
|
|
223
|
+
async function runTasks() {
|
|
224
|
+
locked = true;
|
|
225
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
226
|
+
const tasks = await client.zrangebyscore(RedisKey, 0, Date.now());
|
|
227
|
+
if (tasks.length > 0) {
|
|
228
|
+
await client.zrem(RedisKey, ...tasks);
|
|
229
|
+
for (const task of tasks) {
|
|
230
|
+
const m = task.match(RetryPattern);
|
|
231
|
+
try {
|
|
232
|
+
if (m && handlers.has(m[2])) {
|
|
233
|
+
await handlers.get(m[2])?.(m[3]);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
console.error(err);
|
|
238
|
+
if (m) {
|
|
239
|
+
const retryCount = m[1] ? parseInt(m[1], 10) : 0;
|
|
240
|
+
if (retryCount < MaxRetries) {
|
|
241
|
+
await client.zadd(RedisKey, Date.now() + RetryDelayMs, `RETRY-${retryCount + 1}:${m[2]}:${m[3]}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
locked = false;
|
|
248
|
+
await updateTimer();
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAwDA,gCAEC;AAgCD,wCAgBC;AAiBD,0CAEC;AA8BD,0BAcC;AA0BD,gCAMC;AAWD,kCAyBC;AAOD,4BA6BC;AAjRD,+DAA8D;AAC9D,iEAAwD;AASxD,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,IAAI,KAAK,CAAC,g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,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACnC,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,OAAO,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
const chai_1 = require("chai");
|
|
6
|
+
const RedisKey = "SchedulerUtil.Tasks";
|
|
7
|
+
async function cleanupRedis() {
|
|
8
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
9
|
+
await client.del(RedisKey);
|
|
10
|
+
}
|
|
11
|
+
describe("Redis Scheduler - setHandler", () => {
|
|
12
|
+
it("should register a handler", async () => RegisterHandlerTest());
|
|
13
|
+
it("should reject handler names containing :", async () => RejectColonInNameTest());
|
|
14
|
+
});
|
|
15
|
+
describe("Redis Scheduler - addTask", () => {
|
|
16
|
+
it("should add a task to the sorted set", async () => AddTaskTest());
|
|
17
|
+
it("should throw for unknown handler", async () => AddTaskUnknownHandlerTest());
|
|
18
|
+
});
|
|
19
|
+
describe("Redis Scheduler - removeTask", () => {
|
|
20
|
+
it("should remove a task from the sorted set", async () => RemoveTaskTest());
|
|
21
|
+
it("should throw for unknown handler", async () => RemoveTaskUnknownHandlerTest());
|
|
22
|
+
});
|
|
23
|
+
describe("Redis Scheduler - enableListener / disableListener", () => {
|
|
24
|
+
it("should enable and disable the listener", async () => EnableDisableListenerTest());
|
|
25
|
+
it("should use lazyConnect when duplicating client", async () => EnableListenerUsesLazyConnectTest());
|
|
26
|
+
});
|
|
27
|
+
describe("Redis Scheduler - runTasks", () => {
|
|
28
|
+
it("should execute due tasks", async () => RunDueTasksTest());
|
|
29
|
+
it("should not execute future tasks", async () => SkipFutureTasksTest());
|
|
30
|
+
});
|
|
31
|
+
describe("Redis Scheduler - retry logic", () => {
|
|
32
|
+
it("should retry failed tasks up to 3 times", async () => RetryFailedTasksTest());
|
|
33
|
+
});
|
|
34
|
+
async function RegisterHandlerTest() {
|
|
35
|
+
let called = false;
|
|
36
|
+
(0, interface_redis_scheduler_1.setHandler)("test-register", () => {
|
|
37
|
+
called = true;
|
|
38
|
+
});
|
|
39
|
+
(0, chai_1.expect)(called).to.equal(false);
|
|
40
|
+
}
|
|
41
|
+
async function RejectColonInNameTest() {
|
|
42
|
+
try {
|
|
43
|
+
(0, interface_redis_scheduler_1.setHandler)("invalid:name", () => { });
|
|
44
|
+
chai_1.expect.fail("should have thrown");
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
(0, chai_1.expect)(err.message).to.include("may not contain");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function AddTaskTest() {
|
|
51
|
+
await cleanupRedis();
|
|
52
|
+
(0, interface_redis_scheduler_1.setHandler)("test-add", () => { });
|
|
53
|
+
const dueTime = Date.now() + 60000;
|
|
54
|
+
await (0, interface_redis_scheduler_1.addTask)("test-add", dueTime, "task-data");
|
|
55
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
56
|
+
const members = await client.zrange(RedisKey, 0, -1);
|
|
57
|
+
(0, chai_1.expect)(members).to.include("test-add:task-data");
|
|
58
|
+
await cleanupRedis();
|
|
59
|
+
}
|
|
60
|
+
async function AddTaskUnknownHandlerTest() {
|
|
61
|
+
try {
|
|
62
|
+
await (0, interface_redis_scheduler_1.addTask)("nonexistent-handler", Date.now(), "data");
|
|
63
|
+
chai_1.expect.fail("should have thrown");
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
(0, chai_1.expect)(err.message).to.include("Unknown SchedulerUtil handler");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async function RemoveTaskTest() {
|
|
70
|
+
await cleanupRedis();
|
|
71
|
+
(0, interface_redis_scheduler_1.setHandler)("test-remove", () => { });
|
|
72
|
+
const client = await (0, interface_redis_1.GetClient)();
|
|
73
|
+
await client.zadd(RedisKey, Date.now() + 60000, "test-remove:remove-data");
|
|
74
|
+
await (0, interface_redis_scheduler_1.removeTask)("test-remove", "remove-data");
|
|
75
|
+
const members = await client.zrange(RedisKey, 0, -1);
|
|
76
|
+
(0, chai_1.expect)(members).to.not.include("test-remove:remove-data");
|
|
77
|
+
await cleanupRedis();
|
|
78
|
+
}
|
|
79
|
+
async function RemoveTaskUnknownHandlerTest() {
|
|
80
|
+
try {
|
|
81
|
+
await (0, interface_redis_scheduler_1.removeTask)("nonexistent-handler", "data");
|
|
82
|
+
chai_1.expect.fail("should have thrown");
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
(0, chai_1.expect)(err.message).to.include("Unknown SchedulerUtil handler");
|
|
86
|
+
}
|
|
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();
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/tests/index.test.ts"],"names":[],"mappings":";;A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
+
{
|
|
2
|
+
"name": "@antelopejs/interface-redis-scheduler",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "AntelopeJS interface for Redis-based task scheduling",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"antelopejs",
|
|
7
|
+
"interface",
|
|
8
|
+
"redis",
|
|
9
|
+
"scheduler"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/AntelopeJS/interface-redis-scheduler.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"packageManager": "pnpm@10.6.5",
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "rimraf dist && tsc",
|
|
31
|
+
"format": "biome format --write .",
|
|
32
|
+
"lint:fix": "biome check --write .",
|
|
33
|
+
"lint": "biome check .",
|
|
34
|
+
"prepack": "pnpm run build",
|
|
35
|
+
"release": "pnpm run lint && pnpm run prepack && release-it",
|
|
36
|
+
"test": "pnpm run build && ajs module test ."
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@antelopejs/interface-core": "^0.0.2",
|
|
40
|
+
"@antelopejs/interface-redis": "^0.0.2",
|
|
41
|
+
"ioredis": "^5.4.2"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/chai": "^4.3.20",
|
|
45
|
+
"@types/mocha": "^10.0.10",
|
|
46
|
+
"@types/node": "^22.14.1",
|
|
47
|
+
"@biomejs/biome": "2.3.2",
|
|
48
|
+
"chai": "^4.5.0",
|
|
49
|
+
"release-it": "^19.0.2",
|
|
50
|
+
"release-it-changelogen": "^0.1.0",
|
|
51
|
+
"rimraf": "^6.0.1",
|
|
52
|
+
"typescript": "^5.8.3"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"antelopeJs": {
|
|
58
|
+
"test": "src/antelope.test.ts"
|
|
59
|
+
}
|
|
60
|
+
}
|