Skip to content

Commit

Permalink
Ensure any exceptions are logged properly in scheduler.run()
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Dec 7, 2020
1 parent d0e5dd2 commit 7cfb0ec
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions cylc/flow/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,7 @@ async def start_scheduler(self):
raise exc from None

except (KeyboardInterrupt, asyncio.CancelledError, Exception) as exc:
try:
await self.shutdown(exc)
except Exception as exc2:
# In case of exceptions in the shutdown method itself
LOG.exception(exc2)
raise exc from None
await self.handle_exception(exc)

else:
# main loop ends (not used?)
Expand All @@ -644,8 +639,7 @@ async def run(self):
await self.start_servers()
await self.log_start()
except (KeyboardInterrupt, asyncio.CancelledError, Exception) as exc:
await self.shutdown(exc)
raise
await self.handle_exception(exc)
else:
# note start_scheduler handles its own shutdown logic
await self.start_scheduler()
Expand Down Expand Up @@ -1619,16 +1613,19 @@ async def shutdown(self, reason):
"""
if isinstance(reason, SchedulerStop):
LOG.info('Suite shutting down - %s', reason.args[0])
LOG.info(f'Suite shutting down - {reason.args[0]}')
elif isinstance(reason, SchedulerError):
LOG.error('Suite shutting down - %s', reason)
LOG.error(f'Suite shutting down - {reason}')
elif isinstance(reason, SuiteConfigError):
LOG.error(f'{SuiteConfigError.__name__}: {reason}')
elif isinstance(reason, PlatformLookupError):
LOG.error(f'{PlatformLookupError.__name__}: {reason}')
else:
LOG.exception(reason)
LOG.critical('Suite shutting down - %s', reason)
if str(reason):
LOG.critical(f'Suite shutting down - {reason}')
else:
LOG.critical('Suite shutting down')

if self.proc_pool:
self.proc_pool.close()
Expand Down Expand Up @@ -1836,3 +1833,18 @@ def process_cylc_stop_point(self):
if stoppoint is not None:
self.options.stopcp = str(stoppoint)
self.pool.set_stop_point(get_point(self.options.stopcp))

async def handle_exception(self, exc):
"""Gracefully shut down the scheduler.
This re-raises the caught exception, to be caught higher up.
Args:
exc: The caught exception to be logged during the shutdown.
"""
try:
await self.shutdown(exc)
except Exception as exc2:
# In case of exceptions in the shutdown method itself
LOG.exception(exc2)
raise exc from None

0 comments on commit 7cfb0ec

Please sign in to comment.