Demonstration of the Event States

The Event State Class manages the lifecycle of a log event using a finite state machine.

This class encapsulates valid transitions between event states such as receiving, processing, delivery, and failure handling.

It supports automatic and conditional transitions based on success flags.

[8]:
from logprep.ng.event.event_state import EventState

state = EventState()  # Initial start at: RECEIVING
print(state.current_state)
receiving
[9]:
state.next_state()  # switch to: RECEIVED
print(state.current_state)
received
[10]:
state.next_state()  # switch to: PROCESSING
print(state.current_state)
processing
[11]:
if True:
    state.next_state(success=True)  # with SUCCESS: switch to: PROCESSED
    print(state.current_state)
else:
    state.next_state(success=False)  # with FAILURE: switch to: FAILED
    print(state.current_state)

    state.next_state()  # BUT: FAILED state transition mismatch! switch to: STORED_IN_ERROR
    print(state.current_state)
processed
[12]:
state.next_state()  # switch to: STORED_IN_OUTPUT
print(state.current_state)
stored_in_output
[13]:
state.next_state(success=False)  # witch FAILURE: switch to: FAILED
print(state.current_state)
failed
[14]:
state.next_state()  # [In FAIL State] switch to: STORED_IN_ERROR
print(state.current_state)
stored_in_error
[15]:
state.next_state(success=True)  # with SUCCESS: switch to DELIVERED
print(state.current_state)
delivered
[16]:
state.next_state()  # switch to ACKED
print(state.current_state)
acked