Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions openedx/core/djangoapps/programs/tasks/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,9 @@ def award_program_certificates(self, username):
)
except Exception: # pylint: disable=broad-except
# keep trying to award other certs, but retry the whole task to fix any missing entries
warning_message = 'Failed to award certificate for program {uuid} to user {username}.'.format(
uuid=program_uuid, username=username)

if countdown < MAX_RETRIES:
LOGGER.warning(warning_message)
retry = True
else:
LOGGER.exception("Max retries exceeded. {msg}".format(msg=warning_message))
LOGGER.warning('Failed to award certificate for program {uuid} to user {username}.'.format(

@bderusha bderusha Dec 13, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this looks good. Can we also add an additional warning if this is the last attempt

if self.request.retries == MAX_RETRIES:
    LOGGER.exception('Final attempt to award certificate for program %s to user %s failed', program_uuid, username)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

::EDIT::

Actually I think this may not be necessary as you mentioned in the other PR. But we should update our alerting to capture whatever error message is output when MaxRetriesExceededError is thrown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bderusha Got it, thanks.

uuid=program_uuid, username=username))
retry = True

if retry:
# N.B. This logic assumes that this task is idempotent
Expand Down
31 changes: 0 additions & 31 deletions openedx/core/djangoapps/programs/tasks/v1/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,37 +275,6 @@ def test_continue_awarding_certs_if_error(
mock_info.assert_any_call(mock.ANY, 1, self.student.username)
mock_info.assert_any_call(mock.ANY, 2, self.student.username)

@mock.patch(TASKS_MODULE + '.MAX_RETRIES', 0)
def test_retries_exceeded(
self,
mock_get_completed_programs,
mock_get_certified_programs,
mock_award_program_certificate,
):
"""
Checks that a single failure to award one of several certificates
does not cause the entire task to fail. Also ensures that
successfully awarded certs are logged as INFO and exception is logged
for failed requests if retires are exceeded.
"""

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([Exception('boom'), None])

with mock.patch(TASKS_MODULE + '.LOGGER.info') as mock_info, \
mock.patch(TASKS_MODULE + '.LOGGER.exception') as mock_exception:
tasks.award_program_certificates.delay(self.student.username).get(retries=0)

self.assertEqual(mock_award_program_certificate.call_count, 2)

mock_exception.assert_called_once_with(
'Max retries exceeded. Failed to award certificate for program {uuid} to user {username}.'.format(
uuid=1,
username=self.student.username)
)
mock_info.assert_any_call(mock.ANY, 2, self.student.username)

def test_retry_on_programs_api_errors(
self,
mock_get_completed_programs,
Expand Down