Merge branch 'stable' into devel

This commit is contained in:
Matthew Jones
2017-03-08 15:35:09 -05:00
17 changed files with 60 additions and 16 deletions

View File

@@ -322,5 +322,5 @@ register(
help_text=_('Useful to uniquely identify Tower instances.'),
category=_('Logging'),
category_slug='logging',
default=None,
default='',
)

View File

@@ -2,10 +2,11 @@ import json
import logging
import urllib
from channels import Group
from channels import Group, channel_layers
from channels.sessions import channel_session
from channels.handler import AsgiRequest
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
from django.contrib.auth.models import User
@@ -49,11 +50,19 @@ def ws_disconnect(message):
@channel_session
def ws_receive(message):
from awx.main.access import consumer_access
channel_layer_settings = channel_layers.configs[message.channel_layer.alias]
max_retries = channel_layer_settings.get('RECEIVE_MAX_RETRY', settings.CHANNEL_LAYER_RECEIVE_MAX_RETRY)
user_id = message.channel_session.get('user_id', None)
if user_id is None:
logger.error("No valid user found for websocket.")
retries = message.content.get('connect_retries', 0) + 1
message.content['connect_retries'] = retries
message.reply_channel.send({"text": json.dumps({"error": "no valid user"})})
retries_left = max_retries - retries
if retries_left > 0:
message.channel_layer.send(message.channel.name, message.content)
else:
logger.error("No valid user found for websocket.")
return None
user = User.objects.get(pk=user_id)

View File

@@ -880,7 +880,7 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
workflow_node_id=self.workflow_node_id))
return websocket_data
def websocket_emit_status(self, status):
def _websocket_emit_status(self, status):
status_data = dict(unified_job_id=self.id, status=status)
status_data.update(self.websocket_emit_data())
status_data['group_name'] = 'jobs'
@@ -890,6 +890,9 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
status_data['group_name'] = "workflow_events"
emit_channel_notification('workflow_events-' + str(self.workflow_job_id), status_data)
def websocket_emit_status(self, status):
connection.on_commit(lambda: self._websocket_emit_status(status))
def notification_data(self):
return dict(id=self.id,
name=self.name,

View File

@@ -382,7 +382,7 @@ class TaskManager():
))
task_obj.save()
_send_notification_templates(task_obj, 'failed')
connection.on_commit(lambda: task_obj.websocket_emit_status('failed'))
task_obj.websocket_emit_status('failed')
logger.error("Task %s appears orphaned... marking as failed" % task)

View File

@@ -218,7 +218,11 @@ def _send_notification_templates(instance, status_str):
raise ValueError(_("status_str must be either succeeded or failed"))
notification_templates = instance.get_notification_templates()
if notification_templates:
all_notification_templates = set(notification_templates.get('success', []) + notification_templates.get('any', []))
if status_str == 'succeeded':
notification_template_type = 'success'
else:
notification_template_type = 'error'
all_notification_templates = set(notification_templates.get(notification_template_type, []) + notification_templates.get('any', []))
if len(all_notification_templates):
try:
(notification_subject, notification_body) = getattr(instance, 'build_notification_%s_message' % status_str)()