mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
more work
This commit is contained in:
parent
4d2a7a20af
commit
2f2a1063e2
@ -976,8 +976,8 @@ class DB:
|
|||||||
def queue_fts_job(self, book_id, fmt, path, fmt_size, fmt_hash):
|
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)
|
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):
|
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)
|
return self.fts.commit_result(book_id, fmt, fmt_size, fmt_hash, text, err_msg)
|
||||||
|
|
||||||
def shutdown_fts(self):
|
def shutdown_fts(self):
|
||||||
if self.fts_enabled:
|
if self.fts_enabled:
|
||||||
|
@ -469,8 +469,8 @@ class Cache:
|
|||||||
break
|
break
|
||||||
|
|
||||||
@write_api
|
@write_api
|
||||||
def commit_fts_result(self, 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)
|
return self.backend.commit_fts_result(book_id, fmt, fmt_size, fmt_hash, text, err_msg)
|
||||||
|
|
||||||
@api
|
@api
|
||||||
def set_fts_num_of_workers(self, num=None):
|
def set_fts_num_of_workers(self, num=None):
|
||||||
|
@ -86,7 +86,7 @@ class FTS:
|
|||||||
return book_id, fmt
|
return book_id, fmt
|
||||||
return None, None
|
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()
|
conn = self.get_connection()
|
||||||
text_hash = ''
|
text_hash = ''
|
||||||
if text:
|
if text:
|
||||||
|
@ -52,6 +52,7 @@ class Worker(Thread):
|
|||||||
|
|
||||||
code_to_exec = 'from calibre.db.fts.text import main; main({!r})'
|
code_to_exec = 'from calibre.db.fts.text import main; main({!r})'
|
||||||
max_duration = 30 # minutes
|
max_duration = 30 # minutes
|
||||||
|
poll_interval = 0.1 # seconds
|
||||||
|
|
||||||
def __init__(self, jobs_queue, supervise_queue):
|
def __init__(self, jobs_queue, supervise_queue):
|
||||||
super().__init__(name='FTSWorker', daemon=True)
|
super().__init__(name='FTSWorker', daemon=True)
|
||||||
@ -91,14 +92,14 @@ class Worker(Thread):
|
|||||||
)
|
)
|
||||||
while self.keep_going and monotonic() <= time_limit:
|
while self.keep_going and monotonic() <= time_limit:
|
||||||
with suppress(subprocess.TimeoutExpired):
|
with suppress(subprocess.TimeoutExpired):
|
||||||
p.wait(0.1)
|
p.wait(self.poll_interval)
|
||||||
break
|
break
|
||||||
if p.returncode is None:
|
if p.returncode is None:
|
||||||
p.kill()
|
p.kill()
|
||||||
if monotonic() > time_limit:
|
if not self.keep_going:
|
||||||
return Result(job, _('Extracting text from the {0} file of size {1} took too long').format(
|
return
|
||||||
job.fmt, human_readable(job.fmt_size)))
|
return Result(job, _('Extracting text from the {0} file of size {1} took too long').format(
|
||||||
return
|
job.fmt, human_readable(job.fmt_size)))
|
||||||
if os.path.exists(txtpath):
|
if os.path.exists(txtpath):
|
||||||
return Result(job)
|
return Result(job)
|
||||||
with open(errpath, 'rb') as f:
|
with open(errpath, 'rb') as f:
|
||||||
@ -183,13 +184,15 @@ class Pool:
|
|||||||
|
|
||||||
def commit_result(self, result):
|
def commit_result(self, result):
|
||||||
text = result.text
|
text = result.text
|
||||||
|
err_msg = ''
|
||||||
if not result.ok:
|
if not result.ok:
|
||||||
print(f'Failed to get text from book_id: {result.book_id} format: {result.fmt}', file=sys.stderr)
|
print(f'Failed to get text from book_id: {result.book_id} format: {result.fmt}', file=sys.stderr)
|
||||||
print(text, file=sys.stderr)
|
print(text, file=sys.stderr)
|
||||||
|
err_msg = text
|
||||||
text = ''
|
text = ''
|
||||||
db = self.dbref()
|
db = self.dbref()
|
||||||
if db is not None:
|
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):
|
def shutdown(self):
|
||||||
if self.initialized:
|
if self.initialized:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user