mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
Merge pull request #5946 from AlanCoding/work_success_except
Handle error of missing jobs in success callback
This commit is contained in:
commit
cc476541a1
@ -43,6 +43,7 @@ from django.core.mail import send_mail
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.cache import cache
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
# AWX
|
||||
from awx.main.constants import CLOUD_PROVIDERS
|
||||
@ -235,7 +236,11 @@ def _send_notification_templates(instance, status_str):
|
||||
|
||||
@task(bind=True, queue='default')
|
||||
def handle_work_success(self, result, task_actual):
|
||||
instance = UnifiedJob.get_instance_by_type(task_actual['type'], task_actual['id'])
|
||||
try:
|
||||
instance = UnifiedJob.get_instance_by_type(task_actual['type'], task_actual['id'])
|
||||
except ObjectDoesNotExist:
|
||||
logger.warning('Missing job `{}` in success callback.'.format(task_actual['id']))
|
||||
return
|
||||
if not instance:
|
||||
return
|
||||
|
||||
|
||||
@ -2,10 +2,12 @@ from contextlib import contextmanager
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
import mock
|
||||
|
||||
from awx.main.models import (
|
||||
UnifiedJob,
|
||||
Notification,
|
||||
ProjectUpdate
|
||||
)
|
||||
|
||||
from awx.main import tasks
|
||||
@ -31,6 +33,13 @@ def test_send_notifications_job_id(mocker):
|
||||
assert UnifiedJob.objects.get.called_with(id=1)
|
||||
|
||||
|
||||
def test_work_success_callback_missing_job():
|
||||
task_data = {'type': 'project_update', 'id': 9999}
|
||||
with mock.patch('django.db.models.query.QuerySet.get') as get_mock:
|
||||
get_mock.side_effect = ProjectUpdate.DoesNotExist()
|
||||
assert tasks.handle_work_success(None, task_data) is None
|
||||
|
||||
|
||||
def test_send_notifications_list(mocker):
|
||||
patches = list()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user