Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9312099
D5569.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D5569.diff
View Options
diff --git a/swh/web/api/views/origin_save.py b/swh/web/api/views/origin_save.py
--- a/swh/web/api/views/origin_save.py
+++ b/swh/web/api/views/origin_save.py
@@ -69,11 +69,17 @@
:>json string save_task_status: the status of the origin saving task,
either **not created**, **not yet scheduled**, **scheduled**,
**succeeded** or **failed**
+ :>json string visit_date: the date (in iso format) of the visit if a visit
+ occurred, null otherwise.
+ :>json string visit_status: the status of the visit, either **full**,
+ **partial**, **not_found** or **failed** if a visit occurred, null
+ otherwise.
:statuscode 200: no error
:statuscode 400: an invalid visit type or origin url has been provided
:statuscode 403: the provided origin url is blacklisted
:statuscode 404: no save requests have been found for a given origin
+
"""
if request.method == "POST":
diff --git a/swh/web/common/origin_save.py b/swh/web/common/origin_save.py
--- a/swh/web/common/origin_save.py
+++ b/swh/web/common/origin_save.py
@@ -184,7 +184,7 @@
if i != len(visit_dates):
visit_date = visit_dates[i]
visit_status = origin_visits[i]["status"]
- if origin_visits[i]["status"] not in ("full", "partial", "not_found"):
+ if visit_status not in ("full", "partial", "not_found"):
visit_date = None
except Exception as exc:
sentry_sdk.capture_exception(exc)
@@ -206,7 +206,8 @@
"""
visit_date, visit_status = _get_visit_info_for_save_request(save_request)
save_request.visit_date = visit_date
- if visit_date and visit_status is not None:
+ save_request.visit_status = visit_status
+ if visit_date and visit_status in ("full", "partial"):
# visit has been performed, mark the saving task as succeeded
save_task_status = SAVE_TASK_SUCCEEDED
elif visit_status in ("created", "ongoing"):
@@ -247,8 +248,8 @@
if task:
save_task_status = _save_task_status[task["status"]]
if task_run:
-
save_task_status = _save_task_run_status[task_run["status"]]
+
# Consider request from which a visit date has already been found
# as succeeded to avoid retrieving it again
if save_task_status == SAVE_TASK_SCHEDULED and visit_date:
@@ -259,6 +260,7 @@
):
visit_date, visit_status = _get_visit_info_for_save_request(save_request)
save_request.visit_date = visit_date
+ save_request.visit_status = visit_status
if visit_status in ("failed", "not_found"):
save_task_status = SAVE_TASK_FAILED
must_save = True
diff --git a/swh/web/tests/api/views/test_origin_save.py b/swh/web/tests/api/views/test_origin_save.py
--- a/swh/web/tests/api/views/test_origin_save.py
+++ b/swh/web/tests/api/views/test_origin_save.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2019 The Software Heritage developers
+# Copyright (C) 2018-2021 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information
@@ -18,6 +18,8 @@
SAVE_TASK_NOT_YET_SCHEDULED,
SAVE_TASK_SCHEDULED,
SAVE_TASK_SUCCEEDED,
+ VISIT_STATUS_FAILED,
+ VISIT_STATUS_FULL,
SaveOriginRequest,
SaveUnauthorizedOrigin,
)
@@ -130,6 +132,7 @@
scheduler_task_status="next_run_not_scheduled",
scheduler_task_run_status=None,
visit_date=None,
+ visit_status=None,
):
mock_scheduler = mocker.patch("swh.web.common.origin_save.scheduler")
mock_scheduler.get_tasks.return_value = [
@@ -166,12 +169,13 @@
mock_visit_date = mocker.patch(
("swh.web.common.origin_save." "_get_visit_info_for_save_request")
)
- mock_visit_date.return_value = (visit_date, None)
+ mock_visit_date.return_value = (visit_date, visit_status)
response = check_api_get_responses(api_client, url, status_code=200)
save_request_data = response.data[0]
assert save_request_data["save_request_status"] == expected_request_status
assert save_request_data["save_task_status"] == expected_task_status
+ assert save_request_data["visit_status"] == visit_status
# Check that save task status is still available when
# the scheduler task has been archived
@@ -179,6 +183,7 @@
response = check_api_get_responses(api_client, url, status_code=200)
save_request_data = response.data[0]
assert save_request_data["save_task_status"] == expected_task_status
+ assert save_request_data["visit_status"] == visit_status
def test_save_request_rejected(api_client, mocker):
@@ -251,6 +256,7 @@
scheduler_task_status="completed",
scheduler_task_run_status="eventful",
visit_date=visit_date,
+ visit_status=VISIT_STATUS_FULL,
)
@@ -280,6 +286,7 @@
expected_task_status=SAVE_TASK_FAILED,
scheduler_task_status="disabled",
scheduler_task_run_status="failed",
+ visit_status=VISIT_STATUS_FAILED,
)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 2, 10:42 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3224956
Attached To
D5569: Populate the visit status value in save code now request
Event Timeline
Log In to Comment