Merge pull request #14971 from edx/ahsan/ECOM-4478-Stop-program-cert-awarding-task-from-retrying-on-4xx

Stop program cert awarding if cert is not configured in credentials
This commit is contained in:
Ahsan Ulhaq
2017-04-28 13:57:40 +05:00
committed by GitHub
2 changed files with 23 additions and 0 deletions

View File

@@ -6,6 +6,7 @@ from celery.utils.log import get_task_logger # pylint: disable=no-name-in-modul
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured
from edx_rest_api_client import exceptions
from edx_rest_api_client.client import EdxRestApiClient
from provider.oauth2.models import Client
@@ -196,6 +197,11 @@ def award_program_certificates(self, username):
try:
award_program_certificate(credentials_client, username, program_uuid)
LOGGER.info('Awarded certificate for program %s to user %s', program_uuid, username)
except exceptions.HttpNotFoundError:
LOGGER.exception(
'Certificate for program %s not configured, unable to award certificate to %s',
program_uuid, username
)
except Exception: # pylint: disable=broad-except
# keep trying to award other certs, but retry the whole task to fix any missing entries
LOGGER.exception('Failed to award certificate for program %s to user %s', program_uuid, username)

View File

@@ -7,6 +7,7 @@ from celery.exceptions import MaxRetriesExceededError
import ddt
from django.conf import settings
from django.test import override_settings, TestCase
from edx_rest_api_client import exceptions
from edx_rest_api_client.client import EdxRestApiClient
from edx_oauth2_provider.tests.factories import ClientFactory
import httpretty
@@ -299,3 +300,19 @@ class AwardProgramCertificatesTestCase(CatalogIntegrationMixin, CredentialsApiCo
tasks.award_program_certificates.delay(self.student.username).get()
self.assertEqual(mock_get_certified_programs.call_count, 2)
self.assertEqual(mock_award_program_certificate.call_count, 1)
def test_no_retry_on_credentials_api_not_found_errors(
self,
mock_get_completed_programs,
mock_get_certified_programs,
mock_award_program_certificate,
):
mock_get_completed_programs.return_value = [1, 2]
mock_get_certified_programs.side_effect = [[], [2]]
mock_award_program_certificate.side_effect = self._make_side_effect(
[exceptions.HttpNotFoundError(), None]
)
tasks.award_program_certificates.delay(self.student.username).get()
self.assertEqual(mock_award_program_certificate.call_count, 2)