def perform_work(self, body):
    try:
        flush = (body.get('event') == 'FLUSH')
        if flush:
            self.last_event = ''
        if (not flush):
            event_map = {'job_id': JobEvent, 'ad_hoc_command_id': AdHocCommandEvent, 'project_update_id': ProjectUpdateEvent, 'inventory_update_id': InventoryUpdateEvent, 'system_job_id': SystemJobEvent}
            job_identifier = 'unknown job'
            for (key, cls) in event_map.items():
                if (key in body):
                    job_identifier = body[key]
                    break
            self.last_event = f'''
	- {cls.__name__} for #{job_identifier} ({body.get('event', '')} {body.get('uuid', '')})'''
            if (body.get('event') == 'EOF'):
                try:
                    final_counter = body.get('final_counter', 0)
                    logger.info('Event processing is finished for Job {}, sending notifications'.format(job_identifier))
                    emit_channel_notification('jobs-summary', dict(group_name='jobs', unified_job_id=job_identifier, final_counter=final_counter))
                    uj = UnifiedJob.objects.get(pk=job_identifier)
                    if isinstance(uj, Job):
                        pass
                    elif hasattr(uj, 'send_notification_templates'):
                        handle_success_and_failure_notifications.apply_async([uj.id])
                except Exception:
                    logger.exception('Worker failed to emit notifications: Job {}'.format(job_identifier))
                return
            event = cls.create_from_data(**body)
            self.buff.setdefault(cls, []).append(event)
        retries = 0
        while (retries <= self.MAX_RETRIES):
            try:
                self.flush(force=flush)
                break
            except (OperationalError, InterfaceError, InternalError):
                if (retries >= self.MAX_RETRIES):
                    logger.exception('Worker could not re-establish database connectivity, giving up on one or more events.')
                    return
                delay = (60 * retries)
                logger.exception('Database Error Saving Job Event, retry #{i} in {delay} seconds:'.format(i=(retries + 1), delay=delay))
                django_connection.close()
                time.sleep(delay)
                retries += 1
            except DatabaseError:
                logger.exception('Database Error Saving Job Event')
                break
    except Exception as exc:
        tb = traceback.format_exc()
        logger.error('Callback Task Processor Raised Exception: %r', exc)
        logger.error('Detail: {}'.format(tb))
def perform_work(self, body):
    try:
        flush = (body.get('event') == 'FLUSH')
        if flush:
            self.last_event = 
        if (not flush):
            event_map = {'job_id': JobEvent, 'ad_hoc_command_id': AdHocCommandEvent, 'project_update_id': ProjectUpdateEvent, 'inventory_update_id': InventoryUpdateEvent, 'system_job_id': SystemJobEvent}
            job_identifier = 'unknown job'
            for (key, cls) in event_map.items():
                if (key in body):
                    job_identifier = body[key]
                    break
            self.last_event = f'
	- {cls.__name__} for #{job_identifier} ({body.get('event', )} {body.get('uuid', )})'
            if (body.get('event') == 'EOF'):
                try:
                    final_counter = body.get('final_counter', 0)
                    logger.info('Event processing is finished for Job {}, sending notifications'.format(job_identifier))
                    emit_channel_notification('jobs-summary', dict(group_name='jobs', unified_job_id=job_identifier, final_counter=final_counter))
                    uj = UnifiedJob.objects.get(pk=job_identifier)
                    if isinstance(uj, Job):
                        pass
                    elif hasattr(uj, 'send_notification_templates'):
                        handle_success_and_failure_notifications.apply_async([uj.id])
                except Exception:
                    logger.exception('Worker failed to emit notifications: Job {}'.format(job_identifier))
                return
            event = cls.create_from_data(**body)
            self.buff.setdefault(cls, []).append(event)
        retries = 0
        while (retries <= self.MAX_RETRIES):
            try:
                self.flush(force=flush)
                break
            except (OperationalError, InterfaceError, InternalError):
                if (retries >= self.MAX_RETRIES):
                    logger.exception('Worker could not re-establish database connectivity, giving up on one or more events.')
                    return
                delay = (60 * retries)
                logger.exception('Database Error Saving Job Event, retry #{i} in {delay} seconds:'.format(i=(retries + 1), delay=delay))
                django_connection.close()
                time.sleep(delay)
                retries += 1
            except DatabaseError:
                logger.exception('Database Error Saving Job Event')
                break
    except Exception as exc:
        tb = traceback.format_exc()
        logger.error('Callback Task Processor Raised Exception: %r', exc)
        logger.error('Detail: {}'.format(tb))