Commit 22e91bcc by Calen Pennington

Retry Programs tasks when connection to the API is disabled

parent 36b0c593
......@@ -147,13 +147,13 @@ def award_program_certificates(self, username):
LOGGER.warning(
'Task award_program_certificates cannot be executed when program certification is disabled in API config',
)
return
raise self.retry(countdown=countdown, max_retries=config.max_retries)
if not CredentialsApiConfig.current().is_learner_issuance_enabled:
LOGGER.warning(
'Task award_program_certificates cannot be executed when credentials issuance is disabled in API config',
)
return
raise self.retry(countdown=countdown, max_retries=config.max_retries)
try:
try:
......
......@@ -3,6 +3,7 @@ Tests for programs celery tasks.
"""
import ddt
from celery.exceptions import MaxRetriesExceededError
from django.conf import settings
from django.test import override_settings, TestCase
from edx_rest_api_client.client import EdxRestApiClient
......@@ -250,7 +251,7 @@ class AwardProgramCertificatesTestCase(TestCase, ProgramsApiConfigMixin, Credent
('credentials', 'enable_learner_issuance'),
)
@ddt.unpack
def test_abort_if_config_disabled(
def test_retry_if_config_disabled(
self,
disabled_config_type,
disabled_config_attribute,
......@@ -262,7 +263,8 @@ class AwardProgramCertificatesTestCase(TestCase, ProgramsApiConfigMixin, Credent
"""
getattr(self, 'create_{}_config'.format(disabled_config_type))(**{disabled_config_attribute: False})
with mock.patch(TASKS_MODULE + '.LOGGER.warning') as mock_warning:
tasks.award_program_certificates.delay(self.student.username).get()
with self.assertRaises(MaxRetriesExceededError):
tasks.award_program_certificates.delay(self.student.username).get()
self.assertTrue(mock_warning.called)
for mock_helper in mock_helpers:
self.assertFalse(mock_helper.called)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment