mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow aborting running conversion jobs
This commit is contained in:
parent
eda257421f
commit
9bb972a2ad
@ -179,6 +179,8 @@ def conversion_status(ctx, rd, job_id):
|
|||||||
job_status.last_check_at = monotonic()
|
job_status.last_check_at = monotonic()
|
||||||
if job_status.running:
|
if job_status.running:
|
||||||
percent, msg = job_status.current_status
|
percent, msg = job_status.current_status
|
||||||
|
if rd.query.get('abort_job'):
|
||||||
|
ctx.abort_job(job_id)
|
||||||
return {'running': True, 'percent': percent, 'msg': msg}
|
return {'running': True, 'percent': percent, 'msg': msg}
|
||||||
|
|
||||||
del conversion_jobs[job_id]
|
del conversion_jobs[job_id]
|
||||||
|
@ -45,6 +45,9 @@ class Context(object):
|
|||||||
def job_status(self, job_id):
|
def job_status(self, job_id):
|
||||||
return self.jobs_manager.job_status(job_id)
|
return self.jobs_manager.job_status(job_id)
|
||||||
|
|
||||||
|
def abort_job(self, job_id):
|
||||||
|
return self.jobs_manager.abort_job(job_id)
|
||||||
|
|
||||||
def is_field_displayable(self, field):
|
def is_field_displayable(self, field):
|
||||||
if self.displayed_fields and field not in self.displayed_fields:
|
if self.displayed_fields and field not in self.displayed_fields:
|
||||||
return False
|
return False
|
||||||
|
@ -99,6 +99,8 @@ def show_failure(response):
|
|||||||
|
|
||||||
def on_conversion_status(end_type, xhr, ev):
|
def on_conversion_status(end_type, xhr, ev):
|
||||||
nonlocal current_state
|
nonlocal current_state
|
||||||
|
if current_state is not 'converting' or not container_for_current_state():
|
||||||
|
return # user clicked the back button similar
|
||||||
if end_type is 'load':
|
if end_type is 'load':
|
||||||
response = JSON.parse(xhr.responseText)
|
response = JSON.parse(xhr.responseText)
|
||||||
if response.running:
|
if response.running:
|
||||||
@ -119,8 +121,10 @@ def on_conversion_status(end_type, xhr, ev):
|
|||||||
report_conversion_ajax_failure(xhr)
|
report_conversion_ajax_failure(xhr)
|
||||||
|
|
||||||
|
|
||||||
def check_for_conversion_status():
|
def check_for_conversion_status(abort_job):
|
||||||
query = url_books_query()
|
query = url_books_query()
|
||||||
|
if abort_job:
|
||||||
|
query.abort_job = '1'
|
||||||
data = {}
|
data = {}
|
||||||
ajax_send(f'/conversion/status/{conversion_data.job_id}', data, on_conversion_status, query=query)
|
ajax_send(f'/conversion/status/{conversion_data.job_id}', data, on_conversion_status, query=query)
|
||||||
|
|
||||||
@ -145,6 +149,8 @@ def create_converting_markup():
|
|||||||
_('Converting, please wait...'),
|
_('Converting, please wait...'),
|
||||||
E.div(E.progress()),
|
E.div(E.progress()),
|
||||||
E.div('\xa0', class_='progress-msg'),
|
E.div('\xa0', class_='progress-msg'),
|
||||||
|
E.div('\xa0'),
|
||||||
|
E.div(_('Click the close button in the top left corner to abort the conversion')),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -265,6 +271,11 @@ def fetch_conversion_data(book_id, input_fmt, output_fmt):
|
|||||||
|
|
||||||
|
|
||||||
def on_close(container_id):
|
def on_close(container_id):
|
||||||
|
nonlocal current_state
|
||||||
|
if current_state is 'converting':
|
||||||
|
check_for_conversion_status(True)
|
||||||
|
current_state = 'initializing'
|
||||||
|
apply_state_to_markup()
|
||||||
back()
|
back()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user