-
Notifications
You must be signed in to change notification settings - Fork 5
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
Prevent stuck videos from carrying over to next download session ["unavailable fragments" ?] #193
Changes from 8 commits
4731503
106bc84
6bf33f1
0f9d435
2992049
fefdbff
59e671e
5d604e6
1855e33
b482073
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -95,6 +95,12 @@ def run(self, worker_thread): | |||
if error: | ||||
log.error("[xklb] An error occurred while trying to download %s: %s", error[1], error[0]) | ||||
self.message = f"{error[1]} failed to download: {error[0]}" | ||||
else: | ||||
log.error("No error found in the database, likely the video failed due to unavailable fragments.") | ||||
self.message = f"{self.media_url_link} failed to download: No path or error found in the database (likely the video failed due to unavailable fragments?)" | ||||
media_id = conn.execute("SELECT id FROM media WHERE webpath = ?", (self.media_url,)).fetchone()[0] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is one record with this webpath guaranteed to exist in the media table, even when the query at line 89 returned no records? Since the query above has the extra condition If the query fails, trying to access field
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I understand your point well. I am confident one record with this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reviewed how the media table is created and updated by xklb, and it seems that a record with Could there be cases where the child process fails before updating the database? If it's possible (even if rare), then this query will return 0 records, and this code should defensively check before trying to access the result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The running of the child process alone attests the existence of calibre-web/scripts/lb-wrapper Line 84 in b854132
|
||||
conn.execute("DELETE FROM media WHERE webpath = ?", (self.media_url,)) | ||||
conn.execute("DELETE FROM captions WHERE media_id = ?", (media_id,)) | ||||
return | ||||
except sqlite3.Error as db_error: | ||||
log.error("An error occurred while trying to connect to the database: %s", db_error) | ||||
|
@@ -111,6 +117,7 @@ def run(self, worker_thread): | |||
# 2024-02-17: Dedup Design Evolving... https://github.com/iiab/calibre-web/pull/125 | ||||
conn.execute("UPDATE media SET path = ? WHERE webpath = ?", (new_video_path, self.media_url)) | ||||
conn.execute("UPDATE media SET webpath = ? WHERE path = ?", (f"{self.media_url}×tamp={int(datetime.now().timestamp())}", new_video_path)) | ||||
conn.commit() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I verified this too: commit() is required if the sqlite3 connection is in autocommit=False mode, which is the recommended value. But it seems that autocommit =False is not the current default: No change required here, but it's probably best to set autocommit=False on all sqlite connections? Otherwise, a crash happening between these two UPDATE statements would leave the database in an inconsistent state. I also noticed that the with sqlite3.connect(XKLB_DB_FILE) as conn:
...transactions done here...
# conn is implicitly closed when leaving the with block
conn.close() # this additional close has no effect and can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FYI, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading the docs on how sqlite3.Connection objects interact with context managers, I realize that it doesn't work the same of with sqlite3.connect(XKLB_DB_FILE) as conn:
# ^-- the above context manager will implicitly start an SQL transaction
...queries executed here are part of the transaction...
# The transaction is committed, equivalent to `conn.commit()`
conn.close() # Still needed because the with block leaves the connection open See: https://docs.python.org/3/library/sqlite3.html#how-to-use-the-connection-context-manager There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words: you don't need to add |
||||
self.progress = 1.0 | ||||
else: | ||||
log.error("Failed to send the requested file to %s", self.original_url) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal should be very complete diagnostic hints in both... logs and in "Tasks" view error messages:
@deldesir: what log.error message is best?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best, but the use of self.media_url_link here is not appropriate in a log message. Use self.media_url instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, go ahead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @deldesir: please enact
self.media_url
if that's best, and test!