From 3a875b079cddaa8f3a2cbb02e2333a7461586bb6 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 31 Jul 2023 08:59:50 +0300 Subject: don't notify it's broken and I don't understand why Sponsored-by: author --- ick2/buildsm.py | 63 ++++++++++++++++++++++++--------------------------------- 1 file changed, 26 insertions(+), 37 deletions(-) (limited to 'ick2') diff --git a/ick2/buildsm.py b/ick2/buildsm.py index 9177e09..8d71fde 100644 --- a/ick2/buildsm.py +++ b/ick2/buildsm.py @@ -17,15 +17,14 @@ import ick2 -BUILD_TRIGGERED = 'triggered' -BUILD_BUILDING = 'building' -BUILD_NOTIFYING = 'notifying' -BUILD_DONE = 'done' -BUILD_FAILED = 'failed' +BUILD_TRIGGERED = "triggered" +BUILD_BUILDING = "building" +BUILD_NOTIFYING = "notifying" +BUILD_DONE = "done" +BUILD_FAILED = "failed" class StateMachine: - def __init__(self, get_state, set_state): self.transitions = {} self.get_state = get_state @@ -48,7 +47,6 @@ class StateMachine: class BuildStateMachine: - def __init__(self, build): self.build = build self.sm = self.init_sm() @@ -80,10 +78,10 @@ class BuildStateMachine: return sm def get_state(self): - return self.build.resource['status'] + return self.build.resource["status"] def set_state(self, state): - self.build.resource['status'] = state + self.build.resource["status"] = state def handle_event(self, event): old_state = self.get_state() @@ -101,7 +99,7 @@ class BuildStateMachine: graph = self.build.get_graph() action_ids = graph.find_actions(ick2.ACTION_READY) if not action_ids: # pragma: no cover - self.build.resource['exit_code'] = 0 + self.build.resource["exit_code"] = 0 return BUILD_DONE, None action_id = action_ids[0] @@ -113,7 +111,7 @@ class BuildStateMachine: graph = self.build.get_graph() action_ids = graph.find_actions(ick2.ACTION_READY) if not action_ids: # pragma: no cover - self.build.resource['exit_code'] = 0 + self.build.resource["exit_code"] = 0 return BUILD_DONE, None action_id = action_ids[0] @@ -122,34 +120,32 @@ class BuildStateMachine: return BUILD_NOTIFYING, (action_id, action) def mark_action_done(self, event): - self.build.resource['exit_code'] = event.exit_code + self.build.resource["exit_code"] = event.exit_code graph = self.build.get_graph() graph.set_action_status(event.action_id, ick2.ACTION_DONE) graph.unblock() if graph.has_more_to_do(): return BUILD_BUILDING, None - - self.add_notification_action() - return BUILD_NOTIFYING, None + return BUILD_DONE, None def add_notification_action(self): action = { - 'action': 'notify', + "action": "notify", } graph = self.build.get_graph() graph.append_action(action, ick2.ACTION_READY, depends=[]) def mark_notification_done(self, event): if event.exit_code not in (0, None): # pragma: no cover - self.build.resource['exit_code'] = event.exit_code + self.build.resource["exit_code"] = event.exit_code graph = self.build.get_graph() graph.set_action_status(event.action_id, ick2.ACTION_DONE) graph.unblock() if graph.has_more_to_do(): # pragma: no cover return BUILD_NOTIFYING, None - if self.build.resource.get('exit_code') in (0, None): - self.build.resource['exit_code'] = 0 + if self.build.resource.get("exit_code") in (0, None): + self.build.resource["exit_code"] = 0 return BUILD_DONE, None return BUILD_FAILED, None @@ -157,9 +153,9 @@ class BuildStateMachine: def mark_build_failed(self, event): graph = self.build.get_graph() graph.set_action_status(event.action_id, ick2.BUILD_FAILED) - self.build.resource['exit_code'] = event.exit_code + self.build.resource["exit_code"] = event.exit_code self.add_notification_action() - return BUILD_NOTIFYING, None + return BUILD_FAILED, None # Thing should be something we can create a BuildEvent from. @@ -171,8 +167,8 @@ def create_build_event(thing): return NeedWorkEvent() if isinstance(thing, dict): - exit_code = thing.get('exit_code') - action_id = thing.get('action_id') + exit_code = thing.get("exit_code") + action_id = thing.get("action_id") if exit_code is None: return PartialActionOutputEvent() if exit_code == 0: @@ -181,31 +177,26 @@ def create_build_event(thing): class BuildEvent: # pragma: no cover - - event_type = 'BuildEvent' + event_type = "BuildEvent" def __str__(self): return self.event_type class BuildStartsEvent(BuildEvent): - - event_type = 'build-starts' + event_type = "build-starts" class NeedWorkEvent(BuildEvent): - - event_type = 'need-work' + event_type = "need-work" class PartialActionOutputEvent(BuildEvent): - - event_type = 'partial-output' + event_type = "partial-output" class ActionFinishedEvent(BuildEvent): - - event_type = 'action-finished' + event_type = "action-finished" def __init__(self, action_id): self.action_id = action_id @@ -213,8 +204,7 @@ class ActionFinishedEvent(BuildEvent): class ActionFailedEvent(BuildEvent): - - event_type = 'action-failed' + event_type = "action-failed" def __init__(self, action_id, exit_code): self.action_id = action_id @@ -222,6 +212,5 @@ class ActionFailedEvent(BuildEvent): class UnexpectedEvent(Exception): # pragma: no cover - def __init__(self, event, state): - super().__init__('Did not expect %s in %s' % (event, state)) + super().__init__("Did not expect %s in %s" % (event, state)) -- cgit v1.2.1