Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
5a2b3e69
Commit
5a2b3e69
authored
10 months ago
by
Bastien Abadie
Committed by
Erwan Rouchet
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Reconnect on default DB at end of export
parent
81a5ada2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2327
Reconnect on default DB at end of export
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/documents/export/__init__.py
+22
-4
22 additions, 4 deletions
arkindex/documents/export/__init__.py
with
22 additions
and
4 deletions
arkindex/documents/export/__init__.py
+
22
−
4
View file @
5a2b3e69
...
...
@@ -11,6 +11,7 @@ from pathlib import Path
from
django.conf
import
settings
from
django.core.mail
import
send_mail
from
django.db
import
connections
from
django.db.utils
import
InterfaceError
,
OperationalError
from
django.template.loader
import
render_to_string
from
django.utils.text
import
slugify
from
django_rq
import
job
...
...
@@ -118,6 +119,22 @@ def send_email(subject, template_name, corpus_export, **context):
logger
.
error
(
f
"
Failed to send email to
{
corpus_export
.
user
.
email
}
"
)
def
update_state
(
corpus_export
:
CorpusExport
,
state
:
CorpusExportState
):
"""
Make sure the corpus export instance from default DB is still available for updates
Sometimes the DB connection may drop after a really long export, especially with remote DB exports
"""
try
:
corpus_export
.
state
=
state
corpus_export
.
save
()
except
(
InterfaceError
,
OperationalError
)
as
e
:
logger
.
warning
(
f
"
Database connection has been lost, retrying:
{
e
}
"
)
connections
[
"
default
"
].
connect
()
corpus_export
.
refresh_from_db
(
using
=
"
default
"
)
corpus_export
.
state
=
state
corpus_export
.
save
()
@job
(
"
export
"
,
timeout
=
settings
.
RQ_TIMEOUTS
[
"
export_corpus
"
])
def
export_corpus
(
corpus_export
:
CorpusExport
)
->
None
:
_
,
db_path
=
tempfile
.
mkstemp
(
suffix
=
"
.db
"
)
...
...
@@ -181,8 +198,8 @@ def export_corpus(corpus_export: CorpusExport) -> None:
},
)
corpus_export
.
state
=
CorpusExportState
.
Done
corpus_export
.
save
(
)
# Safely update state with auto-reconnect to db
update_state
(
corpus_export
,
CorpusExportState
.
Done
)
send_email
(
"
Arkindex project export completed
"
,
...
...
@@ -190,8 +207,9 @@ def export_corpus(corpus_export: CorpusExport) -> None:
corpus_export
,
)
except
Exception
as
e
:
corpus_export
.
state
=
CorpusExportState
.
Failed
corpus_export
.
save
()
# Safely update state with auto-reconnect to db
update_state
(
corpus_export
,
CorpusExportState
.
Failed
)
send_email
(
"
Arkindex project export failed
"
,
"
export_error.html
"
,
...
...
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