mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 20:39:59 +00:00
Add some error handling
This commit is contained in:
parent
6a8ae9c0c4
commit
bec280c6b1
@ -84,10 +84,8 @@ class WorkerThread(threading.Thread):
|
|||||||
|
|
||||||
# sometimes tasks (like Upload) don't actually have work to do and are created as already finished
|
# sometimes tasks (like Upload) don't actually have work to do and are created as already finished
|
||||||
if item.stat is STAT_WAITING:
|
if item.stat is STAT_WAITING:
|
||||||
try:
|
# CalibreTask.start() should wrap all exceptions in it's own error handling
|
||||||
item.start(self)
|
item.start(self)
|
||||||
except Exception as e:
|
|
||||||
log.exception(e)
|
|
||||||
|
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
@ -127,7 +125,14 @@ class CalibreTask:
|
|||||||
def start(self, *args):
|
def start(self, *args):
|
||||||
self.start_time = datetime.now()
|
self.start_time = datetime.now()
|
||||||
self.stat = STAT_STARTED
|
self.stat = STAT_STARTED
|
||||||
self.run(*args)
|
|
||||||
|
# catch any unhandled exceptions in a task and automatically fail it
|
||||||
|
try:
|
||||||
|
self.run(*args)
|
||||||
|
except Exception as e:
|
||||||
|
self._handleError(str(e))
|
||||||
|
log.exception(e)
|
||||||
|
|
||||||
self.end_time = datetime.now()
|
self.end_time = datetime.now()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -144,7 +149,8 @@ class CalibreTask:
|
|||||||
|
|
||||||
@progress.setter
|
@progress.setter
|
||||||
def progress(self, x):
|
def progress(self, x):
|
||||||
# todo: throw error if outside of [0,1]
|
if not 0 <= x <= 1:
|
||||||
|
raise ValueError("Task progress should within [0, 1] range")
|
||||||
self._progress = x
|
self._progress = x
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user