Skip to content

Commit

Permalink
Merge pull request #1087 from ProcessMaker/bugfix/FOUR-4186
Browse files Browse the repository at this point in the history
 Watcher stops working, after adding record in the record list
  • Loading branch information
caleeli authored Oct 15, 2021
2 parents 688e7b8 + 08943b7 commit 6881dd4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 56 deletions.
3 changes: 2 additions & 1 deletion src/DataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export default {

return this.post(
endpoint.replace('{id}', id) + query,
params
params,
{ timeout: 60000 }
);
},
};
5 changes: 0 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
22 changes: 10 additions & 12 deletions src/mixins/formWatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down
51 changes: 17 additions & 34 deletions src/mixins/watchers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import Mustache from 'mustache';

const broadcastEvent = '.Illuminate\\\\Notifications\\\\Events\\\\BroadcastNotificationCreated';

const debounce_time = 1000;

export default {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
},
Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/specs/Watchers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
}));
Expand Down Expand Up @@ -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: [
{
Expand Down

0 comments on commit 6881dd4

Please sign in to comment.