From 68fa3c013d8b46751d5b1c74046b86b35a82d547 Mon Sep 17 00:00:00 2001 From: rammohan-y <37395033+rammohan-y@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:10:30 +0530 Subject: [PATCH] Feat/902: executing giveUpAction when noResponseGiveupTimeout is reached (#908) * feat/893: made noResponseTimeout and noResponseGiveUpTimout independent * support for giveUpActions implemented * feat/902: using makeTask and exec of task to execute the giveUpActions * feat/902: changed version of verb-specifications and speech-utils * feat/902: fixed jslint errors * feat/902: modified log * feat/902: using a new event giveupWithTasks for processing giveUpActions * feat/902: removed check for wakeupResolver and replaceApplication already taking care of wakeupResolver, also updated the verb-specifications version * feat/902: removed sync for _onNoResponseGiveUpTimer function --- lib/session/call-session.js | 11 +++++++++++ lib/utils/action-hook-delay.js | 12 +++++++++--- package-lock.json | 29 ++++++++++++++--------------- package.json | 4 ++-- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index e1b8d905..627d0981 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -544,6 +544,17 @@ class CallSession extends Emitter { this.wakeupResolver = null; } }); + this._actionHookDelayProcessor.on('giveupWithTasks', (tasks) => { + this.logger.info('CallSession: ActionHookDelayProcessor: giveupWithTasks event'); + const giveUpTasks = normalizeJambones(this.logger, tasks).map((tdata) => makeTask(this.logger, tdata)); + this.logger.info({tasks: listTaskNames(giveUpTasks)}, 'CallSession:giveupWithTasks task list'); + + // we need to clear the ahd, as we do not want to execute actionHookDelay actions again + this.clearActionHookDelayProcessor(); + + // replace the application with giveUpTasks + this.replaceApplication(giveUpTasks); + }); } catch (err) { this.logger.error({err}, 'CallSession: Error creating ActionHookDelayProcessor'); } diff --git a/lib/utils/action-hook-delay.js b/lib/utils/action-hook-delay.js index 35bb26de..de1cb358 100644 --- a/lib/utils/action-hook-delay.js +++ b/lib/utils/action-hook-delay.js @@ -52,6 +52,7 @@ class ActionHookDelayProcessor extends Emitter { this.retries = opts.retries || 0; this.noResponseTimeout = opts.noResponseTimeout; this.noResponseGiveUpTimeout = opts.noResponseGiveUpTimeout; + this.giveUpActions = opts.giveUpActions; // return false if these options actually disable the ahdp return ('enable' in opts && opts.enable === true) || @@ -165,9 +166,14 @@ class ActionHookDelayProcessor extends Emitter { _onNoResponseGiveUpTimer() { this._active = false; - this.logger.info('ActionHookDelayProcessor#_onNoResponseGiveUpTimer'); - this.stop().catch((err) => {}); - this.emit('giveup'); + if (!this.giveUpActions) { + this.logger.info('ActionHookDelayProcessor#_onNoResponseGiveUpTimer'); + this.stop().catch((err) => {}); + this.emit('giveup'); + } else { + this.logger.info('ActionHookDelayProcessor#_onNoResponseGiveUpTimer - giveUpActions'); + this.emit('giveupWithTasks', this.giveUpActions); + } } } diff --git a/package-lock.json b/package-lock.json index 3e068c58..e9971f81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,10 +15,10 @@ "@jambonz/http-health-check": "^0.0.1", "@jambonz/mw-registrar": "^0.2.7", "@jambonz/realtimedb-helpers": "^0.8.8", - "@jambonz/speech-utils": "^0.1.15", + "@jambonz/speech-utils": "^0.1.16", "@jambonz/stats-collector": "^0.1.10", "@jambonz/time-series": "^0.2.9", - "@jambonz/verb-specifications": "^0.0.76", + "@jambonz/verb-specifications": "^0.0.81", "@opentelemetry/api": "^1.8.0", "@opentelemetry/exporter-jaeger": "^1.23.0", "@opentelemetry/exporter-trace-otlp-http": "^0.50.0", @@ -1536,10 +1536,9 @@ } }, "node_modules/@jambonz/speech-utils": { - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.1.15.tgz", - "integrity": "sha512-TICSKVqFqjc1Ty08Wr+byMQv1g/Piku0x/4cuw25JB3nrOolW/sLABRxoPOUUpbY5EGjXhaVT52FpazCopiIxg==", - "license": "MIT", + "version": "0.1.16", + "resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.1.16.tgz", + "integrity": "sha512-en1ZwDbjDJkeQJ9Ro1l3arYDPYrLnK9OTXQQ7ZjTfqzUipgu0mkTnaUCTzW9taozaBJ4+YelSA1PNg2MtLzVAw==", "dependencies": { "@aws-sdk/client-polly": "^3.496.0", "@aws-sdk/client-sts": "^3.496.0", @@ -1575,9 +1574,9 @@ } }, "node_modules/@jambonz/verb-specifications": { - "version": "0.0.76", - "resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.76.tgz", - "integrity": "sha512-7s61qAsG07xLLaEAHW236rSYzEoh9Qg0aRWHPbTfxCsuTKDNeq+5EwGAShDU5R5ZpjgweZJLhArQm8Ym+4xJ2A==", + "version": "0.0.81", + "resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.81.tgz", + "integrity": "sha512-lufYMLpwaejF3zl8FNy1SvmsxFHXNXU8p7I+GoiwbgOHmFeOX4bQla4RD7bNLFvfjSXPRc2u9h5fceicVa9dcg==", "dependencies": { "debug": "^4.3.4", "pino": "^8.8.0" @@ -10500,9 +10499,9 @@ } }, "@jambonz/speech-utils": { - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.1.15.tgz", - "integrity": "sha512-TICSKVqFqjc1Ty08Wr+byMQv1g/Piku0x/4cuw25JB3nrOolW/sLABRxoPOUUpbY5EGjXhaVT52FpazCopiIxg==", + "version": "0.1.16", + "resolved": "https://registry.npmjs.org/@jambonz/speech-utils/-/speech-utils-0.1.16.tgz", + "integrity": "sha512-en1ZwDbjDJkeQJ9Ro1l3arYDPYrLnK9OTXQQ7ZjTfqzUipgu0mkTnaUCTzW9taozaBJ4+YelSA1PNg2MtLzVAw==", "requires": { "@aws-sdk/client-polly": "^3.496.0", "@aws-sdk/client-sts": "^3.496.0", @@ -10538,9 +10537,9 @@ } }, "@jambonz/verb-specifications": { - "version": "0.0.76", - "resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.76.tgz", - "integrity": "sha512-7s61qAsG07xLLaEAHW236rSYzEoh9Qg0aRWHPbTfxCsuTKDNeq+5EwGAShDU5R5ZpjgweZJLhArQm8Ym+4xJ2A==", + "version": "0.0.81", + "resolved": "https://registry.npmjs.org/@jambonz/verb-specifications/-/verb-specifications-0.0.81.tgz", + "integrity": "sha512-lufYMLpwaejF3zl8FNy1SvmsxFHXNXU8p7I+GoiwbgOHmFeOX4bQla4RD7bNLFvfjSXPRc2u9h5fceicVa9dcg==", "requires": { "debug": "^4.3.4", "pino": "^8.8.0" diff --git a/package.json b/package.json index 8875cd04..f4f81eb0 100644 --- a/package.json +++ b/package.json @@ -31,10 +31,10 @@ "@jambonz/http-health-check": "^0.0.1", "@jambonz/mw-registrar": "^0.2.7", "@jambonz/realtimedb-helpers": "^0.8.8", - "@jambonz/speech-utils": "^0.1.15", + "@jambonz/speech-utils": "^0.1.16", "@jambonz/stats-collector": "^0.1.10", "@jambonz/time-series": "^0.2.9", - "@jambonz/verb-specifications": "^0.0.76", + "@jambonz/verb-specifications": "^0.0.81", "@opentelemetry/api": "^1.8.0", "@opentelemetry/exporter-jaeger": "^1.23.0", "@opentelemetry/exporter-trace-otlp-http": "^0.50.0",