Skip to content

Commit

Permalink
Catch and log non-fatal archive error
Browse files Browse the repository at this point in the history
But do not re-raise or add error to csp config which marks the
adapter as in an unsupported state. Archive failure is not
critical.
  • Loading branch information
smarlowucf committed Jan 10, 2024
1 parent f946719 commit 4285f5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
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

0 comments on commit 4285f5a

Please sign in to comment.