Skip to content

Commit

Permalink
Merge tag '2022-10-28_ingest_bg_task' into develop
Browse files Browse the repository at this point in the history
Fixes to reporting and recovery of remote article ingest
  • Loading branch information
Steven-Eardley committed Oct 28, 2022
2 parents 4b86982 + 2dc2f0a commit 339b74d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions portality/tasks/ingestarticles.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from portality import models
from portality.core import app
from portality.crosswalks.exceptions import CrosswalkException
Expand Down Expand Up @@ -114,7 +116,7 @@ def http_upload(job, path, file_upload):
try:
r = requests.get(file_upload.filename, stream=True)
if r.status_code != requests.codes.ok:
job.add_audit_message("The URL could not be accessed")
job.add_audit_message("The URL could not be accessed. Status: {0}, Content: {1}".format(r.status_code, r.text))
file_upload.failed("The URL could not be accessed")
return False

Expand Down Expand Up @@ -191,9 +193,11 @@ def run(self):

try:
# if the file "exists", this means its a remote file that needs to be downloaded, so do that
if file_upload.status == "exists":
# if it's in "failed" state already but filename has a scheme, this is a retry of a download
if file_upload.status == "exists" or (file_upload.status == "failed" and re.match(r'^(ht|f)tps?://', file_upload.filename)):
job.add_audit_message("Downloading file for file upload {x}, job {y}".format(x=file_upload_id, y=job.id))
self._download(file_upload)
if self._download(file_upload) is False:
raise BackgroundException("Remote file download failed.")

# if the file is validated, which will happen if it has been uploaded, or downloaded successfully, process it.
if file_upload.status == "validated":
Expand Down

0 comments on commit 339b74d

Please sign in to comment.