mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 17:17:58 +00:00
apply interim config changes on barge in
This commit is contained in:
@@ -51,7 +51,9 @@ class Cognigy extends Task {
|
|||||||
this.timeoutCount = 0;
|
this.timeoutCount = 0;
|
||||||
// create a task queue so we can execute our taskss subsequently
|
// create a task queue so we can execute our taskss subsequently
|
||||||
// also executing tasks whenever they come in
|
// also executing tasks whenever they come in
|
||||||
|
|
||||||
this.taskQueue = queue({concurrency: 1, autostart: 1});
|
this.taskQueue = queue({concurrency: 1, autostart: 1});
|
||||||
|
this.changeConfigTasks = [];
|
||||||
|
|
||||||
// keep track of turns so we only do gather once per turn
|
// keep track of turns so we only do gather once per turn
|
||||||
this.turn = 0;
|
this.turn = 0;
|
||||||
@@ -77,7 +79,13 @@ class Cognigy extends Task {
|
|||||||
this.taskQueue.push(async(cb) => {
|
this.taskQueue.push(async(cb) => {
|
||||||
this.logger.debug('executing task from queue');
|
this.logger.debug('executing task from queue');
|
||||||
try {
|
try {
|
||||||
|
|
||||||
const result = await boundTask();
|
const result = await boundTask();
|
||||||
|
// if this is a config task, remove it from the config task storage,
|
||||||
|
// as we have now executed it
|
||||||
|
if(task.isConfigTask){
|
||||||
|
this.changeConfigTasks.shift();
|
||||||
|
}
|
||||||
resolver(result);
|
resolver(result);
|
||||||
cb(result);
|
cb(result);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -87,6 +95,11 @@ class Cognigy extends Task {
|
|||||||
}
|
}
|
||||||
this.logger.debug('say task executed from queue');
|
this.logger.debug('say task executed from queue');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// if this is a config task, lets also push the config
|
||||||
|
if(task.isConfigTask){
|
||||||
|
this.changeConfigTasks.push(task);
|
||||||
|
}
|
||||||
if (this.taskQueue.lastPromise) {
|
if (this.taskQueue.lastPromise) {
|
||||||
// resolve the previous promise for cleanup
|
// resolve the previous promise for cleanup
|
||||||
this.taskQueue.lastPromise.resolve({});
|
this.taskQueue.lastPromise.resolve({});
|
||||||
@@ -344,9 +357,11 @@ class Cognigy extends Task {
|
|||||||
case 'setSessionConfig':
|
case 'setSessionConfig':
|
||||||
// change session params in the order they come in with the say tasks
|
// change session params in the order they come in with the say tasks
|
||||||
// so we are consistent with the flow logic executed within cognigy
|
// so we are consistent with the flow logic executed within cognigy
|
||||||
this._enqueueTask(async() => {
|
const updateConfigTask = () => {
|
||||||
if (evt?.data?.config?.session) this.config.update(evt.data.config.session);
|
if (evt?.data?.config?.session) this.config.update(evt.data.config.session);
|
||||||
});
|
};
|
||||||
|
updateConfigTask.isConfigTask = true;
|
||||||
|
this._enqueueTask(updateConfigTask);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -371,6 +386,11 @@ class Cognigy extends Task {
|
|||||||
// clear task queue, resolve the last promise and cleanup;
|
// clear task queue, resolve the last promise and cleanup;
|
||||||
this.taskQueue.lastPromise.resolve();
|
this.taskQueue.lastPromise.resolve();
|
||||||
this.taskQueue.end();
|
this.taskQueue.end();
|
||||||
|
while(this.changeConfigTasks.length > 0){
|
||||||
|
// apply all the config tasks FIFO
|
||||||
|
const changeConfigTask = this.changeConfigTasks.shift();
|
||||||
|
changeConfigTask();
|
||||||
|
}
|
||||||
this.taskQueue.autostart = true;
|
this.taskQueue.autostart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user