@motiadev/adapter-redis-cron 0.11.2-beta.156 → 0.11.2-beta.157-492501
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 +4 -2
- package/dist/redis-cron-adapter.d.ts.map +1 -1
- package/dist/redis-cron-adapter.js +39 -43
- package/dist/types.d.ts +1 -10
- 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,uBAAuB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CronAdapter, CronLock, CronLockInfo } from '@motiadev/core';
|
|
2
|
-
import type
|
|
2
|
+
import { type RedisClientOptions, type RedisClientType } from 'redis';
|
|
3
|
+
import type { RedisCronAdapterOptions } from './types';
|
|
3
4
|
export declare class RedisCronAdapter implements CronAdapter {
|
|
4
5
|
private client;
|
|
5
6
|
private keyPrefix;
|
|
@@ -9,7 +10,8 @@ export declare class RedisCronAdapter implements CronAdapter {
|
|
|
9
10
|
private instanceId;
|
|
10
11
|
private enableHealthCheck;
|
|
11
12
|
private connected;
|
|
12
|
-
|
|
13
|
+
private isExternalClient;
|
|
14
|
+
constructor(redisConnection: RedisClientType | RedisClientOptions, options?: RedisCronAdapterOptions);
|
|
13
15
|
private connect;
|
|
14
16
|
private ensureConnected;
|
|
15
17
|
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;AACzE,OAAO,EAAgB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,OAAO,CAAA;AAEnF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAMtD,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;IACzB,OAAO,CAAC,gBAAgB,CAAS;gBAErB,eAAe,EAAE,eAAe,GAAG,kBAAkB,EAAE,OAAO,CAAC,EAAE,uBAAuB;YAuCtF,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,46 +3,42 @@ 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
|
+
}
|
|
6
9
|
class RedisCronAdapter {
|
|
7
|
-
constructor(
|
|
10
|
+
constructor(redisConnection, options) {
|
|
8
11
|
this.connected = false;
|
|
9
|
-
this.keyPrefix =
|
|
10
|
-
this.lockTTL =
|
|
11
|
-
this.lockRetryDelay =
|
|
12
|
-
this.lockRetryAttempts =
|
|
13
|
-
this.instanceId =
|
|
14
|
-
this.enableHealthCheck =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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();
|
|
12
|
+
this.keyPrefix = options?.keyPrefix || 'motia:cron:lock:';
|
|
13
|
+
this.lockTTL = options?.lockTTL || 300000;
|
|
14
|
+
this.lockRetryDelay = options?.lockRetryDelay || 1000;
|
|
15
|
+
this.lockRetryAttempts = options?.lockRetryAttempts || 0;
|
|
16
|
+
this.instanceId = options?.instanceId || `motia-${(0, uuid_1.v4)()}`;
|
|
17
|
+
this.enableHealthCheck = options?.enableHealthCheck ?? true;
|
|
18
|
+
if (isRedisClient(redisConnection)) {
|
|
19
|
+
this.client = redisConnection;
|
|
20
|
+
this.isExternalClient = true;
|
|
21
|
+
this.connected = this.client.isOpen;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const config = redisConnection;
|
|
25
|
+
this.isExternalClient = false;
|
|
26
|
+
this.client = (0, redis_1.createClient)(config);
|
|
27
|
+
this.client.on('error', (err) => {
|
|
28
|
+
console.error('[Redis Cron] Client error:', err);
|
|
29
|
+
});
|
|
30
|
+
this.client.on('connect', () => {
|
|
31
|
+
this.connected = true;
|
|
32
|
+
});
|
|
33
|
+
this.client.on('disconnect', () => {
|
|
34
|
+
console.warn('[Redis Cron] Disconnected');
|
|
35
|
+
this.connected = false;
|
|
36
|
+
});
|
|
37
|
+
this.client.on('reconnecting', () => {
|
|
38
|
+
console.log('[Redis Cron] Reconnecting...');
|
|
39
|
+
});
|
|
40
|
+
this.connect();
|
|
41
|
+
}
|
|
46
42
|
}
|
|
47
43
|
async connect() {
|
|
48
44
|
if (!this.connected && !this.client.isOpen) {
|
|
@@ -169,7 +165,7 @@ class RedisCronAdapter {
|
|
|
169
165
|
const result = await this.client.ping();
|
|
170
166
|
return result === 'PONG';
|
|
171
167
|
}
|
|
172
|
-
catch
|
|
168
|
+
catch {
|
|
173
169
|
return false;
|
|
174
170
|
}
|
|
175
171
|
}
|
|
@@ -191,7 +187,7 @@ class RedisCronAdapter {
|
|
|
191
187
|
}
|
|
192
188
|
}
|
|
193
189
|
}
|
|
194
|
-
if (this.client.isOpen) {
|
|
190
|
+
if (!this.isExternalClient && this.client.isOpen) {
|
|
195
191
|
await this.client.quit();
|
|
196
192
|
}
|
|
197
193
|
}
|
|
@@ -221,15 +217,15 @@ class RedisCronAdapter {
|
|
|
221
217
|
}
|
|
222
218
|
async scanKeys(pattern) {
|
|
223
219
|
const keys = [];
|
|
224
|
-
let cursor = 0;
|
|
220
|
+
let cursor = '0';
|
|
225
221
|
do {
|
|
226
|
-
const result = await this.client.scan(cursor, {
|
|
222
|
+
const result = await this.client.scan(cursor.toString(), {
|
|
227
223
|
MATCH: pattern,
|
|
228
224
|
COUNT: 100,
|
|
229
225
|
});
|
|
230
226
|
cursor = result.cursor;
|
|
231
227
|
keys.push(...result.keys);
|
|
232
|
-
} while (cursor !== 0);
|
|
228
|
+
} while (String(cursor) !== '0');
|
|
233
229
|
return keys;
|
|
234
230
|
}
|
|
235
231
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
host?: string;
|
|
3
|
-
port?: number;
|
|
4
|
-
password?: string;
|
|
5
|
-
username?: string;
|
|
6
|
-
database?: number;
|
|
1
|
+
export interface RedisCronAdapterOptions {
|
|
7
2
|
keyPrefix?: string;
|
|
8
3
|
lockTTL?: number;
|
|
9
4
|
lockRetryDelay?: number;
|
|
10
5
|
lockRetryAttempts?: number;
|
|
11
6
|
instanceId?: string;
|
|
12
7
|
enableHealthCheck?: boolean;
|
|
13
|
-
socket?: {
|
|
14
|
-
reconnectStrategy?: (retries: number) => number | Error;
|
|
15
|
-
connectTimeout?: number;
|
|
16
|
-
};
|
|
17
8
|
}
|
|
18
9
|
//# 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,uBAAuB;IACtC,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;CAC5B"}
|
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.2-beta.
|
|
6
|
+
"version": "0.11.2-beta.157-492501",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"redis": "^
|
|
8
|
+
"redis": "^5.9.0",
|
|
9
9
|
"uuid": "^11.1.0",
|
|
10
|
-
"@motiadev/core": "0.11.2-beta.
|
|
10
|
+
"@motiadev/core": "0.11.2-beta.157-492501"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/node": "^22.10.2",
|