Handle CancelledErrors in coordinator
@@ -65,10 +65,12 @@ class Coordinator(Trigger, LogBase):
return task is not None and not task.done()
async def cancel(self):
+ # TODO: Add tests for cancel
task = self._sync_task
if task is not None and not task.done():
task.cancel()
await wait([task])
+ str(task)
def nextSyncAttempt(self):
if self._global_info._last_error is not None:
@@ -117,7 +119,7 @@ class Coordinator(Trigger, LogBase):
return info
async def _sync_wrapper(self):
- self._sync_task = create_task(self._sync())
+ self._sync_task = create_task(self._sync(), name="Internal sync worker")
await wait([self._sync_task])
async def _sync(self):
@@ -129,7 +131,12 @@ class Coordinator(Trigger, LogBase):
self._global_info.success()
self._backoff.reset()
self._global_info.setSkipSpaceCheckOnce(False)
- except Exception as e:
+ except BaseException as e:
+ self.handleError(e)
+ finally:
+ self._updateFreshness()
+
+ def handleError(self, e):
if isinstance(e, CancelledError):
e = UserCancelledError()
if isinstance(e, KnownError):
@@ -157,7 +164,6 @@ class Coordinator(Trigger, LogBase):
text = "much later"
self.info("I'll try again {0}".format(text))
- self._updateFreshness()
def snapshots(self) -> List[Snapshot]:
ret = list(self._model.snapshots.values())
