@ductape/sdk 0.1.115 → 0.1.116
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 +2 -0
- package/dist/index.js +26 -5
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -300,6 +300,8 @@ export default class Ductape implements IDuctape {
|
|
|
300
300
|
private defaultProduct?;
|
|
301
301
|
private defaultEnv?;
|
|
302
302
|
private redisClient?;
|
|
303
|
+
/** Prevent every lazy service factory from retrying a Redis URL that already failed. */
|
|
304
|
+
private redisCacheUnavailable;
|
|
303
305
|
private jobsQueue;
|
|
304
306
|
private healthCheckQueue;
|
|
305
307
|
private healthCheckUpdaterQueue;
|
package/dist/index.js
CHANGED
|
@@ -452,7 +452,7 @@ class Ductape {
|
|
|
452
452
|
throw new Error('Redis can only be used in a server environment.');
|
|
453
453
|
}
|
|
454
454
|
// Already connected
|
|
455
|
-
if (this.redisClient) {
|
|
455
|
+
if (this.redisClient || this.redisCacheUnavailable) {
|
|
456
456
|
return;
|
|
457
457
|
}
|
|
458
458
|
// No Redis URL provided
|
|
@@ -462,17 +462,36 @@ class Ductape {
|
|
|
462
462
|
}
|
|
463
463
|
try {
|
|
464
464
|
const Redis = await this.loadRedis();
|
|
465
|
-
|
|
466
|
-
maxRetriesPerRequest:
|
|
465
|
+
const candidate = new Redis.default(this.redis_url, {
|
|
466
|
+
maxRetriesPerRequest: 1,
|
|
467
467
|
lazyConnect: true,
|
|
468
|
+
enableOfflineQueue: false,
|
|
469
|
+
connectTimeout: 2000,
|
|
470
|
+
retryStrategy: () => null,
|
|
468
471
|
});
|
|
472
|
+
// ioredis emits `error` independently of the rejected connect promise.
|
|
473
|
+
// Install a listener before connect so fallback never creates an
|
|
474
|
+
// unhandled event or repeated reconnect noise.
|
|
475
|
+
candidate.on('error', () => undefined);
|
|
476
|
+
this.redisClient = candidate;
|
|
469
477
|
// Attempt to connect
|
|
470
|
-
await
|
|
478
|
+
await candidate.connect();
|
|
479
|
+
this.redisCacheUnavailable = false;
|
|
471
480
|
console.log('[Ductape] Redis connected for caching');
|
|
472
481
|
}
|
|
473
482
|
catch (error) {
|
|
474
|
-
|
|
483
|
+
const failedClient = this.redisClient;
|
|
475
484
|
this.redisClient = undefined;
|
|
485
|
+
this.redisCacheUnavailable = true;
|
|
486
|
+
try {
|
|
487
|
+
if ((failedClient === null || failedClient === void 0 ? void 0 : failedClient.status) !== 'end')
|
|
488
|
+
failedClient === null || failedClient === void 0 ? void 0 : failedClient.disconnect(false);
|
|
489
|
+
}
|
|
490
|
+
catch (_a) {
|
|
491
|
+
// Best-effort cleanup; memory cache remains available.
|
|
492
|
+
}
|
|
493
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
494
|
+
console.warn(`[Ductape] Redis unavailable (${reason}); using in-memory bootstrap cache.`);
|
|
476
495
|
}
|
|
477
496
|
}
|
|
478
497
|
constructor({ accessKey, redis_url, product, env, local, ip_address, language }) {
|
|
@@ -496,6 +515,8 @@ class Ductape {
|
|
|
496
515
|
this._fallbackService = null;
|
|
497
516
|
this._healthcheckService = null;
|
|
498
517
|
this._brokersService = null;
|
|
518
|
+
/** Prevent every lazy service factory from retrying a Redis URL that already failed. */
|
|
519
|
+
this.redisCacheUnavailable = false;
|
|
499
520
|
/** Register and inspect portable application functions used by Feature JSON. */
|
|
500
521
|
this.functions = {
|
|
501
522
|
register: (contract) => functions_1.portableFunctions.register(contract),
|