From 61b918d6ff2fd417c40643813596176509456406 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Thu, 14 Oct 2021 18:05:52 -0400 Subject: [PATCH 1/4] Try fix watcher API call --- src/mixins/formWatchers.js | 22 ++++++++-------- src/mixins/watchers.js | 51 +++++++++++++------------------------- 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/src/mixins/formWatchers.js b/src/mixins/formWatchers.js index 082bc6df1..3abde8388 100644 --- a/src/mixins/formWatchers.js +++ b/src/mixins/formWatchers.js @@ -92,13 +92,22 @@ export default { } globalObject.window.ProcessMaker.apiClient.post(this.watchers_config.api.execute.replace(/script_id\/script_key/, scriptId), { + sync: true, watcher: watcher.uid, data: input, config, + }).then(response => { + this.loadWatcherResponse(watcher.uid, response.data); + }).catch(error => { + this.loadWatcherResponse(watcher.uid, null, error); }); } }, - loadWatcherResponse(watcherUid, response) { + loadWatcherResponse(watcherUid, response, error) { + if (error) { + this.$parent.$refs.watchersSynchronous.error(error); + return; + } if (!this.watchers) { return; } @@ -161,17 +170,6 @@ export default { }, }, mounted() { - if (globalObject.window.ProcessMaker && globalObject.window.ProcessMaker.user) { - const channel = `ProcessMaker.Models.User.${globalObject.window.ProcessMaker.user.id}`; - const event = 'ProcessMaker\\Notifications\\ScriptResponseNotification'; - globalObject.window.Echo.private(channel).notification( - (data) => { - if (data.type === event) { - this.loadWatcherResponse(data.watcher, data.response); - } - }, - ); - } this.processWatchersQueue = debounce(this.processWatchersQueue, 1000); }, destroyed() { diff --git a/src/mixins/watchers.js b/src/mixins/watchers.js index 0d88b9f25..3dc7fbc94 100644 --- a/src/mixins/watchers.js +++ b/src/mixins/watchers.js @@ -1,7 +1,5 @@ import Mustache from 'mustache'; -const broadcastEvent = '.Illuminate\\\\Notifications\\\\Events\\\\BroadcastNotificationCreated'; - const debounce_time = 1000; export default { @@ -43,9 +41,14 @@ export default { scriptId = watcher.script_key; } this.$dataProvider.postScript(scriptId, { + sync: true, watcher: watcher.uid, data: input, config, + }).then(response => { + this.loadWatcherResponse(watcher.uid, response.data); + }).catch(error => { + this.loadWatcherResponse(watcher.uid, null, error); }); }).then((response) => { if (watcher.output_variable) { @@ -97,42 +100,22 @@ export default { }); this.echoListeners.splice(0); }, - loadWatcherResponse(watcherUid, response) { - window.ProcessMaker.apiClient.get(`/scripts/execution/${response.key}`).then((result) => { - const response = result.data; - this.listeners.forEach(({watcher, resolve, exception}) => { - if (watcher.uid === watcherUid) { - if (response.exception) { - exception(response.message); - } else { - resolve(response.output); - } - } - }); - }).catch((error) => { + loadWatcherResponse(watcherUid, response, error = null) { + if (error) { this.$parent.$refs.watchersSynchronous.error(error); + return; + } + this.listeners.forEach(({watcher, resolve, exception}) => { + if (watcher.uid === watcherUid) { + if (response.exception) { + exception(response.message); + } else { + resolve(response.output); + } + } }); }, }, - mounted() { - if (window.ProcessMaker && window.ProcessMaker.user) { - const channel = `ProcessMaker.Models.User.${window.ProcessMaker.user.id}`; - const event = '.ProcessMaker\\Events\\ScriptResponseEvent'; - this.echoListeners.push({ - event, - channel, - broadcastEvent, - }); - window.Echo.private(channel).listen( - event, - (data) => { - if (data.type === event) { - this.loadWatcherResponse(data.watcher, data.response); - } - }, - ); - } - }, destroyed() { this.cleanEchoListeners(); }, From ce1e3aed4f33432d8105ba1b3088fab8dac7a9b7 Mon Sep 17 00:00:00 2001 From: David Callizaya Date: Thu, 14 Oct 2021 18:47:38 -0400 Subject: [PATCH 2/4] Update watchers test --- src/main.js | 5 ----- tests/e2e/specs/Watchers.spec.js | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main.js b/src/main.js index eb9b20016..f618bfb11 100644 --- a/src/main.js +++ b/src/main.js @@ -140,11 +140,6 @@ window.ProcessMaker = { post(url, body) { return new Promise((resolve, reject) => { switch (url) { - case '/scripts/execute/1': - window.Echo.watcherMocks(body, { - key: '1', - }); - break; case '/requests/data_sources/1': resolve({data: { response: [ diff --git a/tests/e2e/specs/Watchers.spec.js b/tests/e2e/specs/Watchers.spec.js index 4b441571f..5b8624346 100644 --- a/tests/e2e/specs/Watchers.spec.js +++ b/tests/e2e/specs/Watchers.spec.js @@ -181,7 +181,7 @@ describe('Watchers', () => { it('Test synchronous watcher', () => { // Mock script response cy.server(); - cy.route('/api/1.0/scripts/execution/1', JSON.stringify({ + cy.route('POST', '/api/1.0/scripts/execute/1', JSON.stringify({ output: { name: 'Steve', }, @@ -225,7 +225,7 @@ describe('Watchers', () => { it('Test asynchronous watcher', () => { // Mock script response cy.server(); - cy.route('/api/1.0/scripts/execution/1', JSON.stringify({ + cy.route('POST', '/api/1.0/scripts/execute/1', JSON.stringify({ output: { name: 'Steve', }, @@ -267,7 +267,7 @@ describe('Watchers', () => { it('Test error in synchronous watcher', () => { // Mock script response cy.server(); - cy.route('/api/1.0/scripts/execution/1', JSON.stringify({ + cy.route('POST', '/api/1.0/scripts/execute/1', JSON.stringify({ exception: 'Exception', message: 'Test exception response', })); @@ -310,7 +310,8 @@ describe('Watchers', () => { cy.server(); cy.loadFromJson('watcher_select_list.json', 0); cy.route( - '/api/1.0/scripts/execution/1', + 'POST', + '/api/1.0/scripts/execute/1', JSON.stringify({ output: [ { From 9a95f547b4e7926143c00c25f2e0ee1968a6a22c Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Thu, 14 Oct 2021 19:23:07 -0400 Subject: [PATCH 3/4] add timeout to scripts --- src/DataProvider.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/DataProvider.js b/src/DataProvider.js index 78d264fba..0aa81d417 100644 --- a/src/DataProvider.js +++ b/src/DataProvider.js @@ -116,7 +116,8 @@ export default { return this.post( endpoint.replace('{id}', id) + query, - params + params, + { timeout: 30000 } ); }, }; \ No newline at end of file From 08943b761d5843ef8be782a719fe97a8eb99152b Mon Sep 17 00:00:00 2001 From: "Marco A. Nina Mena" Date: Thu, 14 Oct 2021 19:29:53 -0400 Subject: [PATCH 4/4] change timeout --- src/DataProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataProvider.js b/src/DataProvider.js index 0aa81d417..f35b55c33 100644 --- a/src/DataProvider.js +++ b/src/DataProvider.js @@ -117,7 +117,7 @@ export default { return this.post( endpoint.replace('{id}', id) + query, params, - { timeout: 30000 } + { timeout: 60000 } ); }, }; \ No newline at end of file