Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
videoag
backend
Commits
05e0fb67
Commit
05e0fb67
authored
2 months ago
by
Simon Künzel
Browse files
Options
Downloads
Patches
Plain Diff
Handle sorter transaction failure better
parent
76c8d3f7
No related branches found
No related tags found
No related merge requests found
Checking pipeline status
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
job_controller/jobs/source_file_sorter/job.py
+21
-2
21 additions, 2 deletions
job_controller/jobs/source_file_sorter/job.py
with
21 additions
and
2 deletions
job_controller/jobs/source_file_sorter/job.py
+
21
−
2
View file @
05e0fb67
...
...
@@ -140,7 +140,14 @@ def _check_files(session: SessionDb) -> list[str]:
return
to_sort_file_db_paths
def
_sort_file
(
session
:
SessionDb
,
own_job_id
:
int
,
db_path
:
str
):
class
FunctionContainer
:
def
__init__
(
self
):
super
().
__init__
()
self
.
func
=
None
def
_sort_file
(
session
:
SessionDb
,
own_job_id
:
int
,
db_path
:
str
,
on_transaction_failure
:
FunctionContainer
):
sorter_file
=
session
.
scalar
(
SorterFile
.
sudo_select
().
where
(
SorterFile
.
file_path
==
db_path
)
)
...
...
@@ -248,6 +255,7 @@ def _sort_file(session: SessionDb, own_job_id: int, db_path: str):
else
:
dest_file
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
shutil
.
move
(
file
,
dest_file
)
on_transaction_failure
.
func
=
lambda
:
shutil
.
move
(
dest_file
,
file
)
# Set AFTER moving the file, as moving is more likely to throw exception than setting the variable
# Note that with an exception the file's variables will still be updated in the database
sorter_file
.
file_path
=
_get_db_path
(
dest_file
)
...
...
@@ -279,6 +287,17 @@ def execute(database, own_job_id, input_data: CJsonObject):
to_sort_file_db_paths
=
database
.
execute_write_transaction_and_commit
(
_check_files
)
for
db_path
in
to_sort_file_db_paths
:
on_transaction_failure
=
FunctionContainer
()
# Sort every file in its own transaction to reduce blocking the database
database
.
execute_write_transaction_and_commit
(
_sort_file
,
own_job_id
,
db_path
)
try
:
database
.
execute_write_transaction_and_commit
(
_sort_file
,
own_job_id
,
db_path
,
)
except
Exception
:
if
on_transaction_failure
.
func
is
not
None
:
try
:
on_transaction_failure
.
func
()
except
Exception
as
e
:
logger
.
warning
(
"
Error while calling failed transaction handler:
"
,
e
)
raise
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment