mirror of
https://github.com/ansible/awx.git
synced 2026-02-24 06:26:00 -03:30
Merge pull request #5946 from AlanCoding/work_success_except
Handle error of missing jobs in success callback
This commit is contained in:
@@ -43,6 +43,7 @@ from django.core.mail import send_mail
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.constants import CLOUD_PROVIDERS
|
from awx.main.constants import CLOUD_PROVIDERS
|
||||||
@@ -235,7 +236,11 @@ def _send_notification_templates(instance, status_str):
|
|||||||
|
|
||||||
@task(bind=True, queue='default')
|
@task(bind=True, queue='default')
|
||||||
def handle_work_success(self, result, task_actual):
|
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:
|
if not instance:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ from contextlib import contextmanager
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
import mock
|
||||||
|
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
UnifiedJob,
|
UnifiedJob,
|
||||||
Notification,
|
Notification,
|
||||||
|
ProjectUpdate
|
||||||
)
|
)
|
||||||
|
|
||||||
from awx.main import tasks
|
from awx.main import tasks
|
||||||
@@ -31,6 +33,13 @@ def test_send_notifications_job_id(mocker):
|
|||||||
assert UnifiedJob.objects.get.called_with(id=1)
|
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):
|
def test_send_notifications_list(mocker):
|
||||||
patches = list()
|
patches = list()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user