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
18 changes: 12 additions & 6 deletions learning_resources_search/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def send_subscription_emails(self, subscription_type, period="daily"):
@app.task(
acks_late=True,
reject_on_worker_lost=True,
autoretry_for=(RetryError, SystemExit),
autoretry_for=(RetryError,),
retry_backoff=True,
rate_limit="600/m",
)
Expand All @@ -301,8 +301,10 @@ def index_learning_resources(ids, resource_type, index_types):
try:
with wrap_retry_exception(*SEARCH_CONN_EXCEPTIONS):
api.index_learning_resources(ids, resource_type, index_types)
except (RetryError, Ignore, SystemExit):
except (RetryError, Ignore):
raise
except SystemExit as err:
raise RetryError(SystemExit.__name__) from err
except: # noqa: E722
error = "index_courses threw an error"
log.exception(error)
Expand Down Expand Up @@ -362,7 +364,7 @@ def bulk_deindex_percolators(ids):
@app.task(
acks_late=True,
reject_on_worker_lost=True,
autoretry_for=(RetryError, SystemExit),
autoretry_for=(RetryError,),
retry_backoff=True,
rate_limit="600/m",
)
Expand All @@ -383,8 +385,10 @@ def bulk_index_percolate_queries(percolate_ids, index_types):
PERCOLATE_INDEX_TYPE,
index_types,
)
except (RetryError, Ignore, SystemExit):
except (RetryError, Ignore):
raise
except SystemExit as err:
raise RetryError(SystemExit.__name__) from err
except: # noqa: E722
error = "bulk_index_percolate_queries threw an error"
log.exception(error)
Expand Down Expand Up @@ -417,7 +421,7 @@ def index_course_content_files(course_ids, index_types):
@app.task(
acks_late=True,
reject_on_worker_lost=True,
autoretry_for=(RetryError, SystemExit),
autoretry_for=(RetryError,),
retry_backoff=True,
rate_limit="600/m",
)
Expand All @@ -441,8 +445,10 @@ def index_content_files(
api.index_content_files(
content_file_ids, learning_resource_id, index_types=index_types
)
except (RetryError, Ignore, SystemExit):
except (RetryError, Ignore):
raise
except SystemExit as err:
raise RetryError(SystemExit.__name__) from err
except: # noqa: E722
error = "index_content_files threw an error"
log.exception(error)
Expand Down
12 changes: 12 additions & 0 deletions learning_resources_search/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,18 @@ def raise_thing():
raise_thing()


def test_system_exit_retry(mocker):
"""Task should raise a retry error on system exit"""
mocker.patch(
"learning_resources_search.tasks.wrap_retry_exception", side_effect=SystemExit
)
with pytest.raises(Retry) as exc:
index_learning_resources.delay(
[1], COURSE_TYPE, IndexestoUpdate.current_index.value
)
assert str(exc.value.args[1]) == "SystemExit"


@pytest.mark.parametrize(
"indexes",
[["course"], ["program"]],
Expand Down
Loading