Skip to content
Merged
Changes from all commits
Commits
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
17 changes: 5 additions & 12 deletions cps/tasks/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def run(self, worker_thread):

except Exception as e:
log.error("An error occurred during the subprocess execution: %s", e)
self.message = f"{self.media_url_link} failed to download: {e}"
self.record_error_in_database(str(e))
self.message = f"{self.media_url_link} failed to download: {self.read_error_from_database()}"

finally:
self.end_time = datetime.now()
Expand All @@ -134,18 +133,12 @@ def run(self, worker_thread):
else:
log.info("No media URL provided - skipping download task")

def record_error_in_database(self, error_message):
"""Record the error in the database"""
def read_error_from_database(self):
"""Read the error from the database"""
with sqlite3.connect(XKLB_DB_FILE) as conn:
# Check if the error column exists, if not, create it at the rightmost position
cursor = conn.cursor()
cursor.execute("PRAGMA table_info(media)")
columns = [column[1] for column in cursor.fetchall()]
if "error" not in columns:
conn.execute("ALTER TABLE media ADD COLUMN error TEXT")
conn.execute("UPDATE media SET error = ? WHERE webpath = ?", (error_message, self.media_url))
conn.commit()
error = conn.execute("SELECT error FROM media WHERE webpath = ?", (self.media_url,)).fetchone()[0]
conn.close()
return error

@property
def name(self):
Expand Down