Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch and log non-fatal archive error #146

Merged
merged 1 commit into from
Jan 11, 2024
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
14 changes: 9 additions & 5 deletions csp_billing_adapter/bill_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,12 @@ def process_metering(
'usage_records': billable_records
}

archive_record(
hook,
config,
billing_record
)
try:
archive_record(
hook,
config,
billing_record
)
except Exception as error:
# Non-fatal error is only logged
log.exception(error)
10 changes: 9 additions & 1 deletion tests/unit/test_bill_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,16 @@ def test_create_billing_status():


@mark.config('config_testing_mixed.yaml')
@mock.patch('csp_billing_adapter.bill_utils.archive_record')
@mock.patch('csp_billing_adapter.utils.time.sleep')
def test_process_metering_legacy_return(mock_sleep, cba_pm, cba_config):
def test_process_metering_legacy_return(
mock_sleep,
mock_archive,
cba_pm,
cba_config
):
mock_archive.side_effect = Exception('Failed to save archive!')

# initialise the cache
create_cache(
hook=cba_pm.hook,
Expand Down
Loading