diff --git a/awx/main/models/mixins.py b/awx/main/models/mixins.py index e2e9959efa..7cf5c9fb86 100644 --- a/awx/main/models/mixins.py +++ b/awx/main/models/mixins.py @@ -570,19 +570,19 @@ class WebhookMixin(models.Model): return service_header = { - 'github': 'Authorization', - 'gitlab': 'PRIVATE-TOKEN', + 'github': ('Authorization', 'token {}'), + 'gitlab': ('PRIVATE-TOKEN', '{}'), } service_statuses = { 'github': { - 'new': 'pending', + 'pending': 'pending', 'successful': 'success', 'failed': 'failure', 'canceled': 'failure', # Github doesn't have a 'canceled' status :( 'error': 'error', }, 'gitlab': { - 'new': 'pending', + 'pending': 'pending', 'running': 'running', 'successful': 'success', 'failed': 'failed', @@ -601,8 +601,9 @@ class WebhookMixin(models.Model): 'state': statuses[status], 'context': 'ansible/awx' if license_type == 'open' else 'ansible/tower', } - headers = {service_header[self.webhook_service]: self.webhook_credential.get_input('token')} - response = requests.post(status_api, data=data, headers=headers) + k, v = service_header[self.webhook_service] + headers = {k: v.format(self.webhook_credential.get_input('token'))} + response = requests.post(status_api, data=json.dumps(data), headers=headers) except Exception: logger.exception("Posting webhook status caused an error.") return @@ -610,4 +611,5 @@ class WebhookMixin(models.Model): if response.status_code < 400: logger.debug("Webhook status update sent.") else: - logger.debug("Posting webhook status failed, code: {}".format(response.status_code)) + logger.error("Posting webhook status failed, code: {}".format(response.status_code)) + logger.error(response.text) diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index b04f151295..ef428bcdfa 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -462,8 +462,6 @@ class JobNotificationMixin(object): return (notification_subject, notification_body) def send_notification_templates(self, status): - self.update_webhook_status(status) - from awx.main.tasks import send_notifications # avoid circular import if status not in ['running', 'succeeded', 'failed']: raise ValueError(_("status must be either running, succeeded or failed")) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index 8ed1b275e7..21459874a1 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -1206,6 +1206,8 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique def websocket_emit_status(self, status): connection.on_commit(lambda: self._websocket_emit_status(status)) + if hasattr(self, 'update_webhook_status'): + connection.on_commit(lambda: self.update_webhook_status(status)) def notification_data(self): return dict(id=self.id, @@ -1422,6 +1424,3 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique def is_isolated(self): return bool(self.controller_node) - - def update_webhook_status(self, status): - return