@motiadev/adapter-redis-cron 0.11.1-beta.156-879726 → 0.11.1-beta.156-491458
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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/redis-cron-adapter.d.ts +2 -4
- package/dist/redis-cron-adapter.d.ts.map +1 -1
- package/dist/redis-cron-adapter.js +43 -39
- package/dist/types.d.ts +10 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CronAdapter, CronLock, CronLockInfo } from '@motiadev/core';
|
|
2
|
-
import
|
|
3
|
-
import type { RedisCronAdapterOptions } from './types';
|
|
2
|
+
import type { RedisCronAdapterConfig } from './types';
|
|
4
3
|
export declare class RedisCronAdapter implements CronAdapter {
|
|
5
4
|
private client;
|
|
6
5
|
private keyPrefix;
|
|
@@ -10,8 +9,7 @@ export declare class RedisCronAdapter implements CronAdapter {
|
|
|
10
9
|
private instanceId;
|
|
11
10
|
private enableHealthCheck;
|
|
12
11
|
private connected;
|
|
13
|
-
|
|
14
|
-
constructor(redisConnection: RedisClientType | RedisClientOptions, options?: RedisCronAdapterOptions);
|
|
12
|
+
constructor(config: RedisCronAdapterConfig);
|
|
15
13
|
private connect;
|
|
16
14
|
private ensureConnected;
|
|
17
15
|
private makeKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-cron-adapter.d.ts","sourceRoot":"","sources":["../src/redis-cron-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"redis-cron-adapter.d.ts","sourceRoot":"","sources":["../src/redis-cron-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AAErD,qBAAa,gBAAiB,YAAW,WAAW;IAClD,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,SAAS,CAAQ;gBAEb,MAAM,EAAE,sBAAsB;YA+C5B,OAAO;YAWP,eAAe;IAM7B,OAAO,CAAC,OAAO;IAIT,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA8CpE,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B1C,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAwCxD,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAc7B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBzB,cAAc,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;YA2BjC,QAAQ;CAevB"}
|
|
@@ -3,42 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RedisCronAdapter = void 0;
|
|
4
4
|
const redis_1 = require("redis");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
|
-
function isRedisClient(input) {
|
|
7
|
-
return typeof input === 'object' && 'isOpen' in input && 'connect' in input;
|
|
8
|
-
}
|
|
9
6
|
class RedisCronAdapter {
|
|
10
|
-
constructor(
|
|
7
|
+
constructor(config) {
|
|
11
8
|
this.connected = false;
|
|
12
|
-
this.keyPrefix =
|
|
13
|
-
this.lockTTL =
|
|
14
|
-
this.lockRetryDelay =
|
|
15
|
-
this.lockRetryAttempts =
|
|
16
|
-
this.instanceId =
|
|
17
|
-
this.enableHealthCheck =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
9
|
+
this.keyPrefix = config.keyPrefix || 'motia:cron:lock:';
|
|
10
|
+
this.lockTTL = config.lockTTL || 300000;
|
|
11
|
+
this.lockRetryDelay = config.lockRetryDelay || 1000;
|
|
12
|
+
this.lockRetryAttempts = config.lockRetryAttempts || 0;
|
|
13
|
+
this.instanceId = config.instanceId || `motia-${(0, uuid_1.v4)()}`;
|
|
14
|
+
this.enableHealthCheck = config.enableHealthCheck ?? true;
|
|
15
|
+
this.client = (0, redis_1.createClient)({
|
|
16
|
+
socket: {
|
|
17
|
+
host: config.host || 'localhost',
|
|
18
|
+
port: config.port || 6379,
|
|
19
|
+
reconnectStrategy: config.socket?.reconnectStrategy ||
|
|
20
|
+
((retries) => {
|
|
21
|
+
if (retries > 10) {
|
|
22
|
+
return new Error('Redis connection retry limit exceeded');
|
|
23
|
+
}
|
|
24
|
+
return Math.min(retries * 100, 3000);
|
|
25
|
+
}),
|
|
26
|
+
connectTimeout: config.socket?.connectTimeout || 10000,
|
|
27
|
+
},
|
|
28
|
+
password: config.password,
|
|
29
|
+
username: config.username,
|
|
30
|
+
database: config.database || 0,
|
|
31
|
+
});
|
|
32
|
+
this.client.on('error', (err) => {
|
|
33
|
+
console.error('[Redis Cron] Client error:', err);
|
|
34
|
+
});
|
|
35
|
+
this.client.on('connect', () => {
|
|
36
|
+
this.connected = true;
|
|
37
|
+
});
|
|
38
|
+
this.client.on('disconnect', () => {
|
|
39
|
+
console.warn('[Redis Cron] Disconnected');
|
|
40
|
+
this.connected = false;
|
|
41
|
+
});
|
|
42
|
+
this.client.on('reconnecting', () => {
|
|
43
|
+
console.log('[Redis Cron] Reconnecting...');
|
|
44
|
+
});
|
|
45
|
+
this.connect();
|
|
42
46
|
}
|
|
43
47
|
async connect() {
|
|
44
48
|
if (!this.connected && !this.client.isOpen) {
|
|
@@ -165,7 +169,7 @@ class RedisCronAdapter {
|
|
|
165
169
|
const result = await this.client.ping();
|
|
166
170
|
return result === 'PONG';
|
|
167
171
|
}
|
|
168
|
-
catch {
|
|
172
|
+
catch (error) {
|
|
169
173
|
return false;
|
|
170
174
|
}
|
|
171
175
|
}
|
|
@@ -187,7 +191,7 @@ class RedisCronAdapter {
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
}
|
|
190
|
-
if (
|
|
194
|
+
if (this.client.isOpen) {
|
|
191
195
|
await this.client.quit();
|
|
192
196
|
}
|
|
193
197
|
}
|
|
@@ -217,15 +221,15 @@ class RedisCronAdapter {
|
|
|
217
221
|
}
|
|
218
222
|
async scanKeys(pattern) {
|
|
219
223
|
const keys = [];
|
|
220
|
-
let cursor =
|
|
224
|
+
let cursor = 0;
|
|
221
225
|
do {
|
|
222
|
-
const result = await this.client.scan(cursor
|
|
226
|
+
const result = await this.client.scan(cursor, {
|
|
223
227
|
MATCH: pattern,
|
|
224
228
|
COUNT: 100,
|
|
225
229
|
});
|
|
226
230
|
cursor = result.cursor;
|
|
227
231
|
keys.push(...result.keys);
|
|
228
|
-
} while (
|
|
232
|
+
} while (cursor !== 0);
|
|
229
233
|
return keys;
|
|
230
234
|
}
|
|
231
235
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface RedisCronAdapterConfig {
|
|
2
|
+
host?: string;
|
|
3
|
+
port?: number;
|
|
4
|
+
password?: string;
|
|
5
|
+
username?: string;
|
|
6
|
+
database?: number;
|
|
2
7
|
keyPrefix?: string;
|
|
3
8
|
lockTTL?: number;
|
|
4
9
|
lockRetryDelay?: number;
|
|
5
10
|
lockRetryAttempts?: number;
|
|
6
11
|
instanceId?: string;
|
|
7
12
|
enableHealthCheck?: boolean;
|
|
13
|
+
socket?: {
|
|
14
|
+
reconnectStrategy?: (retries: number) => number | Error;
|
|
15
|
+
connectTimeout?: number;
|
|
16
|
+
};
|
|
8
17
|
}
|
|
9
18
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,MAAM,CAAC,EAAE;QACP,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,KAAK,CAAA;QACvD,cAAc,CAAC,EAAE,MAAM,CAAA;KACxB,CAAA;CACF"}
|
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"description": "Redis cron adapter for Motia framework, enabling distributed cron job coordination to prevent duplicate executions across multiple instances.",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
-
"version": "0.11.1-beta.156-
|
|
6
|
+
"version": "0.11.1-beta.156-491458",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"redis": "^
|
|
8
|
+
"redis": "^4.7.0",
|
|
9
9
|
"uuid": "^11.1.0",
|
|
10
|
-
"@motiadev/core": "0.11.1-beta.156-
|
|
10
|
+
"@motiadev/core": "0.11.1-beta.156-491458"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "^22.10.2",
|