diff options
author | Andrew Godwin | 2022-11-09 23:48:31 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-09 23:48:31 -0700 |
commit | 2c3a1299709f2612e96c37e4e121c83ad4df7a56 (patch) | |
tree | 89c2aed22a7a10730e02c809f83b744a21e295e1 /stator/runner.py | |
parent | 7746abbbb7700fa918450101bbc6d29ed9b4b608 (diff) | |
download | takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.tar.gz takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.tar.bz2 takahe-2c3a1299709f2612e96c37e4e121c83ad4df7a56.zip |
Profile fetching now working on state machine
Diffstat (limited to 'stator/runner.py')
-rw-r--r-- | stator/runner.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/stator/runner.py b/stator/runner.py index f9c726e..1392e4d 100644 --- a/stator/runner.py +++ b/stator/runner.py @@ -1,6 +1,7 @@ import asyncio import datetime import time +import traceback import uuid from typing import List, Type @@ -53,7 +54,7 @@ class StatorRunner: f"Attempting transition on {instance._meta.label_lower}#{instance.pk}" ) self.tasks.append( - asyncio.create_task(instance.atransition_attempt()) + asyncio.create_task(self.run_transition(instance)) ) self.handled += 1 space_remaining -= 1 @@ -70,5 +71,17 @@ class StatorRunner: print("Complete") return self.handled + async def run_transition(self, instance: StatorModel): + """ + Wrapper for atransition_attempt with fallback error handling + """ + try: + await instance.atransition_attempt() + except BaseException: + traceback.print_exc() + def remove_completed_tasks(self): + """ + Removes all completed asyncio.Tasks from our local in-progress list + """ self.tasks = [t for t in self.tasks if not t.done()] |