Skip to content

Commit

Permalink
Add LogObserver for logging state transitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Feb 26, 2024
1 parent bbf8f49 commit 81fba49
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions atxm/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ class _Machine(StateMachine):
FixedRateSpeedUp,
]

class LogObserver:
"""StateMachine observer for logging information about state/transitions."""
def __init__(self):
self.log = log

def on_transition(self, source, target):
if source.id != target.id:
self.log.debug(f"[transition] {source.name} --> {target.name}")

def __init__(
self,
w3: Web3,
Expand Down Expand Up @@ -121,6 +130,8 @@ def __init__(

super().__init__()

self.add_observer(_Machine.LogObserver())

@property
def _busy(self) -> bool:
"""Returns True if the machine is busy."""
Expand All @@ -144,7 +155,7 @@ def _handle_errors(self, *args, **kwargs):
# State Transitions
@_transition_to_paused.before
def _enter_pause_mode(self):
self.log.warn("[pause] pause activated")
self.log.info("[pause] pause mode activated")
return

@_PAUSED.enter
Expand Down Expand Up @@ -192,7 +203,6 @@ def _process_busy(self):
if self._tx_tracker.pending:
# There is an active transaction
self.__handle_active_transaction()

elif self._tx_tracker.queue:
# There is no active transaction
# and there are queued transactions
Expand Down

0 comments on commit 81fba49

Please sign in to comment.