Skip to content
Snippets Groups Projects
Commit 8c89dcd8 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

backend: Force bundle recooking if it is no longer in cache

It can exist cases when a bundle has been cooked and marked as done in
the vault database but is no longer available in the vault cache.

Previously, when requesting a new cooking of such bundle, the vault
backend was not creating a new cooking task and thus the bundle could
not be downloaded anymore.

So ensure to check bundle presence in cache for such edge case and force
its recooking if it is not the case.

Related to swh/devel/swh-web#4804.
parent 1eaed881
Branches ensure-recook-if-bundle-no-longer-in-cache
No related tags found
No related merge requests found
Pipeline #9791 passed
......@@ -201,8 +201,14 @@ class VaultBackend(VaultDB):
if bundle_type not in COOKER_TYPES:
raise NotFoundExc(f"{bundle_type} is an unknown type.")
# If there's a failed bundle entry, delete it first.
if info is not None and info["task_status"] == "failed":
if info is not None and (
info["task_status"] == "failed"
or (
info["task_status"] == "done"
and not self.cache.is_cached(bundle_type, swhid)
)
):
# If there's a failed bundle entry or bundle no longer in cache, delete it first.
cur.execute(
"DELETE FROM vault_bundle WHERE type = %s AND swhid = %s",
(bundle_type, str(swhid)),
......
......@@ -201,9 +201,11 @@ def test_cook_idempotent(swh_vault, sample_data):
def test_cook_email_pending_done(swh_vault):
with mock_cooking(swh_vault), patch.object(
swh_vault, "add_notif_email"
) as madd, patch.object(swh_vault, "send_notification") as msend:
with (
mock_cooking(swh_vault),
patch.object(swh_vault, "add_notif_email") as madd,
patch.object(swh_vault, "send_notification") as msend,
):
swh_vault.cook(TEST_TYPE, TEST_SWHID)
madd.assert_not_called()
msend.assert_not_called()
......@@ -219,6 +221,7 @@ def test_cook_email_pending_done(swh_vault):
msend.reset_mock()
swh_vault.set_status(TEST_TYPE, TEST_SWHID, "done")
swh_vault.cache.add(TEST_TYPE, TEST_SWHID, b"content")
swh_vault.cook(TEST_TYPE, TEST_SWHID, email=TEST_EMAIL)
msend.assert_called_once_with(None, TEST_EMAIL, TEST_TYPE, TEST_SWHID, "done")
madd.assert_not_called()
......@@ -512,3 +515,24 @@ def test_download_url_cache_http_backend(swh_vault_http_cache, mocker, httpserve
download_url = swh_vault_http_cache.download_url(TEST_TYPE, swhid)
assert download_url is not None
assert requests.get(download_url).content == content
def test_cook_if_status_done_but_bundle_not_in_cache(swh_vault, mocker):
with mock_cooking(swh_vault):
swh_vault.cook(TEST_TYPE, TEST_SWHID, email="a@example.com")
swh_vault.cache.add(TEST_TYPE, TEST_SWHID, b"content")
swh_vault.set_status(TEST_TYPE, TEST_SWHID, "done")
create_task = mocker.spy(swh_vault, "create_task")
with mock_cooking(swh_vault):
swh_vault.cook(TEST_TYPE, TEST_SWHID, email="a@example.com")
create_task.assert_not_called()
swh_vault.cache.delete(TEST_TYPE, TEST_SWHID)
with mock_cooking(swh_vault):
swh_vault.cook(TEST_TYPE, TEST_SWHID, email="a@example.com")
create_task.assert_called_once_with(TEST_TYPE, TEST_SWHID, False)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment