Exemplo n.º 1
0
 def send_notification_templates(self, status_str):
     from awx.main.tasks import send_notifications  # avoid circular import
     if status_str not in ['succeeded', 'failed']:
         raise ValueError(
             _("status_str must be either succeeded or failed"))
     try:
         notification_templates = self.get_notification_templates()
     except Exception:
         logger.warn(
             "No notification template defined for emitting notification")
         notification_templates = None
     if notification_templates:
         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(
                     self, 'build_notification_%s_message' % status_str)()
             except AttributeError:
                 raise NotImplementedError(
                     "build_notification_%s_message() does not exist" %
                     status_str)
             send_notifications.delay([
                 n.generate_notification(notification_subject,
                                         notification_body).id
                 for n in all_notification_templates
             ],
                                      job_id=self.id)
Exemplo n.º 2
0
 def _func():
     send_notifications.delay([
         local_nt.generate_notification(local_subject,
                                        local_body).id
     ],
                              job_id=self.id)
Exemplo n.º 3
0
 def send_it():
     send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
                               for n in all_notification_templates],
                              job_id=self.id)