more work

This commit is contained in:
Kovid Goyal 2022-04-12 17:20:32 +05:30
parent 4d2a7a20af
commit 2f2a1063e2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 14 additions and 11 deletions

View File

@ -976,8 +976,8 @@ class DB:
def queue_fts_job(self, book_id, fmt, path, fmt_size, fmt_hash):
return self.fts.queue_job(book_id, fmt, path, fmt_size, fmt_hash)
def commit_fts_result(self, book_id, fmt, fmt_size, fmt_hash, text):
return self.fts.commit_result(book_id, fmt, fmt_size, fmt_hash, text)
def commit_fts_result(self, book_id, fmt, fmt_size, fmt_hash, text, err_msg):
return self.fts.commit_result(book_id, fmt, fmt_size, fmt_hash, text, err_msg)
def shutdown_fts(self):
if self.fts_enabled:

View File

@ -469,8 +469,8 @@ class Cache:
break
@write_api
def commit_fts_result(self, book_id, fmt, fmt_size, fmt_hash, text):
return self.backend.commit_fts_result(book_id, fmt, fmt_size, fmt_hash, text)
def commit_fts_result(self, book_id, fmt, fmt_size, fmt_hash, text, err_msg):
return self.backend.commit_fts_result(book_id, fmt, fmt_size, fmt_hash, text, err_msg)
@api
def set_fts_num_of_workers(self, num=None):

View File

@ -86,7 +86,7 @@ class FTS:
return book_id, fmt
return None, None
def commit_result(self, book_id, fmt, fmt_size, fmt_hash, text):
def commit_result(self, book_id, fmt, fmt_size, fmt_hash, text, err_msg=''):
conn = self.get_connection()
text_hash = ''
if text:

View File

@ -52,6 +52,7 @@ class Worker(Thread):
code_to_exec = 'from calibre.db.fts.text import main; main({!r})'
max_duration = 30 # minutes
poll_interval = 0.1 # seconds
def __init__(self, jobs_queue, supervise_queue):
super().__init__(name='FTSWorker', daemon=True)
@ -91,14 +92,14 @@ class Worker(Thread):
)
while self.keep_going and monotonic() <= time_limit:
with suppress(subprocess.TimeoutExpired):
p.wait(0.1)
p.wait(self.poll_interval)
break
if p.returncode is None:
p.kill()
if monotonic() > time_limit:
return Result(job, _('Extracting text from the {0} file of size {1} took too long').format(
job.fmt, human_readable(job.fmt_size)))
return
if not self.keep_going:
return
return Result(job, _('Extracting text from the {0} file of size {1} took too long').format(
job.fmt, human_readable(job.fmt_size)))
if os.path.exists(txtpath):
return Result(job)
with open(errpath, 'rb') as f:
@ -183,13 +184,15 @@ class Pool:
def commit_result(self, result):
text = result.text
err_msg = ''
if not result.ok:
print(f'Failed to get text from book_id: {result.book_id} format: {result.fmt}', file=sys.stderr)
print(text, file=sys.stderr)
err_msg = text
text = ''
db = self.dbref()
if db is not None:
db.commit_fts_result(result.book_id, result.fmt, result.fmt_size, result.fmt_hash, text)
db.commit_fts_result(result.book_id, result.fmt, result.fmt_size, result.fmt_hash, text, err_msg)
def shutdown(self):
if self.initialized: