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

DDS-1681: Retry database insert if failed files after upload #656

Merged
merged 100 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
de5c4d8
add UPDATE_FAILED_FILES endpoint
valyo Sep 26, 2023
4a6f1b4
add logic for checking for failed_delivery_log and sending its conten…
valyo Sep 26, 2023
dc57194
remove unused import
valyo Sep 26, 2023
71d5aa9
clean up status and failed dictionary
valyo Sep 28, 2023
40583dc
check if files updated and change status without calling filehandler …
valyo Oct 9, 2023
dc12205
manuall run
rv0lt Sep 20, 2023
c8692c4
start testing
rv0lt Sep 20, 2023
6da8a04
install gcc
rv0lt Sep 20, 2023
3d13b1b
sudo
rv0lt Sep 20, 2023
e8b38f3
check for path
rv0lt Sep 20, 2023
8308e4c
fix dependencies sphinx
rv0lt Sep 20, 2023
4c43e9c
move around
rv0lt Sep 20, 2023
c5b8317
move around
rv0lt Sep 20, 2023
b505fed
move around
rv0lt Sep 20, 2023
a80e1ba
conf py
rv0lt Sep 20, 2023
2111430
test
rv0lt Sep 20, 2023
e049e5c
test
rv0lt Sep 20, 2023
170a718
prebuild
rv0lt Sep 20, 2023
aa143eb
prebuild
rv0lt Sep 20, 2023
9a46424
prebuild
rv0lt Sep 20, 2023
db9eff3
prebuild
rv0lt Sep 20, 2023
2c86723
sudo
rv0lt Sep 20, 2023
ce96a1c
tried in html
rv0lt Sep 20, 2023
1816d61
tried in html
rv0lt Sep 20, 2023
d1d5b8a
move rgsv install
rv0lt Sep 20, 2023
81ba2d2
move python req
rv0lt Sep 20, 2023
dbc0f6d
rgsv must be in prebuild
rv0lt Sep 20, 2023
d89074d
moved building tools·
rv0lt Sep 20, 2023
0825699
add again commented sections
rv0lt Sep 20, 2023
925e204
remove triggering on push branch
rv0lt Sep 20, 2023
9bf4d3c
springlog
rv0lt Sep 20, 2023
5f7e56b
changelog and version
i-oden Sep 22, 2023
0a62676
Generate new screengrabs with rich-codex
github-actions[bot] Sep 22, 2023
9f6ff4f
sprintlog
i-oden Sep 22, 2023
e3ece87
added functionality
rv0lt Sep 26, 2023
dab5304
black
rv0lt Sep 26, 2023
9c0462b
black
rv0lt Sep 26, 2023
730c6c0
sprintlog
rv0lt Sep 27, 2023
cee581b
tests
rv0lt Sep 27, 2023
20c70cd
black
rv0lt Sep 27, 2023
bc296f0
tests
rv0lt Sep 27, 2023
6f51cfe
tests
rv0lt Sep 27, 2023
42b92a8
tests
rv0lt Sep 27, 2023
f3f1e39
tests
rv0lt Sep 27, 2023
93d1c23
more test
rv0lt Sep 28, 2023
4bded6f
forgot atributes
rv0lt Sep 28, 2023
38343ce
increase coverage
rv0lt Sep 28, 2023
ea3f3f4
fix test
rv0lt Sep 28, 2023
dcf13d2
log test
rv0lt Sep 28, 2023
8320ede
more coverage
rv0lt Sep 28, 2023
adb13bc
refactoring
rv0lt Sep 28, 2023
a522cee
go back
rv0lt Sep 28, 2023
9503289
go back
rv0lt Sep 28, 2023
1585fca
init refactoring
rv0lt Sep 28, 2023
97105c2
init refactoring
rv0lt Sep 28, 2023
5ab3605
ref
rv0lt Sep 28, 2023
a2faca3
typo
rv0lt Sep 28, 2023
8173e2b
generalise
rv0lt Sep 28, 2023
ae7a666
typo
rv0lt Sep 28, 2023
0bdd1a4
typo
rv0lt Sep 28, 2023
8d7ac94
refactore project info
rv0lt Sep 28, 2023
0976362
forgot ddelete
rv0lt Sep 28, 2023
74de228
black
rv0lt Sep 28, 2023
01a2ed2
last test
rv0lt Sep 28, 2023
40c3d85
feedback
rv0lt Sep 28, 2023
7c05d0d
added test
rv0lt Sep 28, 2023
7747dab
increase coverage
rv0lt Sep 28, 2023
dd295a3
Update SPRINTLOG.md
rv0lt Sep 28, 2023
6609acd
Update dds_cli/base.py
rv0lt Sep 29, 2023
ef6c15a
feedback
rv0lt Sep 29, 2023
8fc46fe
black
rv0lt Sep 29, 2023
651a1ec
msg
rv0lt Sep 29, 2023
93efdf1
black
rv0lt Sep 29, 2023
8f9a89c
pylint
rv0lt Sep 29, 2023
6a20a43
updated PR template to match the dds_web one, slightly updated
i-oden Sep 28, 2023
8506cbd
links
i-oden Sep 28, 2023
8ad5a95
prettier
i-oden Sep 28, 2023
2935172
uncomment code and fix some pylint stuff
valyo Oct 9, 2023
6b95d46
pylint
valyo Oct 9, 2023
0c16d1d
more pylint
valyo Oct 9, 2023
8af37e8
pylint again
valyo Oct 9, 2023
b1a3309
black
valyo Oct 9, 2023
bc14620
change endpoint name
valyo Oct 11, 2023
e8858c7
Merge branch 'dev' into DDS-1681-handle-failed_delivery_log
valyo Oct 11, 2023
67cde32
add sprintlog
valyo Oct 11, 2023
63f6a98
Update SPRINTLOG.md
valyo Oct 12, 2023
cfd0201
Update dds_cli/data_putter.py
valyo Oct 12, 2023
413417e
Update dds_cli/data_putter.py
valyo Oct 12, 2023
8ff77e1
Update dds_cli/data_putter.py
valyo Oct 12, 2023
9aa9146
Update dds_cli/data_putter.py
valyo Oct 12, 2023
d5a21df
black
valyo Oct 12, 2023
7821c9f
change endpoint to match backend
valyo Oct 17, 2023
a1d2e28
came upon the "--overwrite" issue
valyo Oct 20, 2023
e67a50c
black
valyo Oct 20, 2023
a29700a
changes after handling of "--overwrite"
valyo Oct 24, 2023
f9bc3aa
Merge branch 'dev' into DDS-1681-handle-failed_delivery_log
i-oden Oct 31, 2023
2ababa9
move retry to function
i-oden Oct 31, 2023
2dc4b8a
uncomment in add_file_db
i-oden Oct 31, 2023
8764004
pylint
i-oden Oct 31, 2023
b0664f6
updated log message
i-oden Nov 2, 2023
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
4 changes: 4 additions & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,7 @@ _Nothing merged in CLI during this sprint_

- GitHub Actions to generate the documentation fixed ([#1473])(https://scilifelab.atlassian.net/jira/software/projects/DDS/boards/13?selectedIssue=DDS-1473)
- Print project information and ask user for confirmation when deleting or archiving projects ([#1401])(https://scilifelab.atlassian.net/jira/software/projects/DDS/boards/13?selectedIssue=DDS-1401)

# 2023-10-02 - 2023-10-13

- Make a single last request to update the database in the case of failed files during upload ([#656](https://github.com/ScilifelabDataCentre/dds_cli/pull/656)
1 change: 1 addition & 0 deletions dds_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class DDSEndpoint:
FILE_INFO = BASE_ENDPOINT + "/file/info"
FILE_INFO_ALL = BASE_ENDPOINT + "/file/all/info"
FILE_UPDATE = BASE_ENDPOINT + "/file/update"
FILE_ADD_FAILED = BASE_ENDPOINT + "/file/failed/add"

# Project specific urls
PROJ_ACCESS = BASE_ENDPOINT + "/proj/access"
Expand Down
116 changes: 98 additions & 18 deletions dds_cli/data_putter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import itertools
import logging
import pathlib
import json

# Installed
import boto3
Expand Down Expand Up @@ -169,6 +170,85 @@ def put(
for x in [y.id for y in progress.tasks if y.fields.get("step") != "put"]
]

# Make a single database update for files that have failed
# Json file for failed files should only be created if there has been an error
if putter.failed_delivery_log.is_file():
i-oden marked this conversation as resolved.
Show resolved Hide resolved
LOG.warning(
"Some uploaded files could not be added to the database %s.\n",
str(putter.failed_delivery_log),
)
LOG.warning("Attempting to add the file to the database.")

try:
with putter.failed_delivery_log.open(mode="r", encoding="utf-8") as json_f:
failed = json.load(json_f)
except Exception as e:
LOG.error(f"Failed to load failed delivery log: {e}")
failed = {}
# remove from log any files that failed for other reasons
for file, values in failed.items():
if values.get("status", {}).get("failed_op") != "add_file_db":
failed.pop(file)

# send failed to API endpoint
params = {"project": putter.project}
try:
response, _ = dds_cli.utils.perform_request(
DDSEndpoint.FILE_ADD_FAILED,
method="put",
headers=putter.token,
params=params,
json=failed,
error_message="Failed to add missing files",
)
except (
dds_cli.exceptions.ApiRequestError,
dds_cli.exceptions.ApiResponseError,
dds_cli.exceptions.DDSCLIException,
) as err:
LOG.warning(str(err))
# if not response:
# raise dds_cli.exceptions.ApiResponseError(
# message="Failed to add missing files to database."
# )
files_added = response.get("files_added")
message = response.get("message")
i-oden marked this conversation as resolved.
Show resolved Hide resolved

# get a list of files from the log
files = list(failed.keys())

if message:
# adding the files failed
# check why
# if the files already exist in the database, then everything is fine and we need to clean status
for file, error in message.items():
if error["error"] == "File already in database":
print(f"Error for {file}: {error['error']}")
# LOG.warning("Message from API: %s", message)
if files_added:
missing_files = [file for file in files if file not in files_added]
if missing_files:
print("The following files are missing:", missing_files)
# raise exceptions.NoDataError("Some files could not be added to the database.")
else:
LOG.warning("All files were added to the database.")

LOG.warning("files: %s", files)
LOG.warning("files added: %s", files_added)

for file in files:
i-oden marked this conversation as resolved.
Show resolved Hide resolved
putter.status[file] = {
"cancel": False,
"started": False,
"message": "",
"failed_op": None,
"put": {"started": False, "done": False},
"add_file_db": {"started": False, "done": False},
}
dds_cli.utils.console.print(
"\nAll the uploaded files successfuly added to the database."
)


###############################################################################
# CLASSES ########################################################### CLASSES #
Expand Down Expand Up @@ -250,7 +330,6 @@ def __init__(

# Remove spinner
progress.remove_task(wait_task)

if not self.filehandler.data:
if self.temporary_directory and self.temporary_directory.is_dir():
LOG.debug("Deleting temporary folder %s.", self.temporary_directory)
Expand Down Expand Up @@ -408,22 +487,23 @@ def add_file_db(self, file):

# Send file info to API - post if new file, put if overwrite
request_method = "put" if fileinfo["overwrite"] else "post"
try:
response_json, _ = dds_cli.utils.perform_request(
DDSEndpoint.FILE_NEW,
method=request_method,
params=params,
json=file_info,
headers=self.token,
error_message=f"Failed to add file '{file}' to database",
)
added_to_db, message = (True, response_json)
except (
dds_cli.exceptions.ApiRequestError,
dds_cli.exceptions.ApiResponseError,
dds_cli.exceptions.DDSCLIException,
) as err:
message = str(err)
LOG.warning(message)
# try:
# response_json, _ = dds_cli.utils.perform_request(
# DDSEndpoint.FILE_NEW,
# method=request_method,
# params=params,
# json=file_info,
# headers=self.token,
# error_message=f"Failed to add file '{file}' to database",
# )
# added_to_db, message = (True, response_json)
# except (
# dds_cli.exceptions.ApiRequestError,
# dds_cli.exceptions.ApiResponseError,
# dds_cli.exceptions.DDSCLIException,
# ) as err:
# message = str(err)
# LOG.warning(message)
message = "test"

return added_to_db, message
Loading