From 148b59d6282baad524ac2f5f73439ca8eb84012d Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Mon, 11 Jul 2016 11:11:53 -0700 Subject: [PATCH] Add additional polling if test notification is "pending" --- .../list.controller.js | 64 +++++++++++-------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index 9ea29b7374..c180d8c6a9 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -147,7 +147,9 @@ export default }; scope.testNotification = function(){ - var name = $filter('sanitize')(this.notification_template.name); + var name = $filter('sanitize')(this.notification_template.name), + pending_count = 10; + Rest.setUrl(defaultUrl + this.notification_template.id +'/test/'); Rest.post({}) .then(function (data) { @@ -156,31 +158,7 @@ export default // Using a setTimeout here to wait for the // notification to be processed and for a status // to be returned from the API. - setTimeout(function(){ - var id = data.data.notification, - url = GetBasePath('notifications') + id; - Rest.setUrl(url); - Rest.get() - .then(function (res) { - Wait('stop'); - if(res && res.data && res.data.status && res.data.status === "successful"){ - scope.search(list.iterator); - ngToast.success({ - content: ` ${name}: Notification sent.` - }); - } - else if(res && res.data && res.data.status && res.data.status === "failed"){ - scope.search(list.iterator); - ngToast.danger({ - content: ` ${name}: Notification failed.` - }); - } - else { - ProcessErrors(scope, data, status, null, { hdr: 'Error!', - msg: 'Call to ' + url + ' failed. Notification returned status: ' + status }); - } - }); - } , 5000); + retrieveStatus(data.data.notification); } else { ProcessErrors(scope, data, status, null, { hdr: 'Error!', @@ -192,6 +170,40 @@ export default content: ` ${name}: Notification Failed.`, }); }); + + function retrieveStatus(id){ + setTimeout(function(){ + var url = GetBasePath('notifications') + id; + Rest.setUrl(url); + Rest.get() + .then(function (res) { + if(res && res.data && res.data.status && res.data.status === "successful"){ + scope.search(list.iterator); + ngToast.success({ + content: ` ${name}: Notification sent.` + }); + Wait('stop'); + } + else if(res && res.data && res.data.status && res.data.status === "failed"){ + scope.search(list.iterator); + ngToast.danger({ + content: ` ${name}: Notification failed.` + }); + Wait('stop'); + } + else if(res && res.data && res.data.status && res.data.status === "pending" && pending_count>0){ + pending_count--; + retrieveStatus(id); + } + else { + Wait('stop'); + ProcessErrors(scope, null, status, null, { hdr: 'Error!', + msg: 'Call to test notifications failed.' }); + } + + }); + } , 5000); + } }; scope.addNotification = function(){