Skip to content

Refactor: Fix circular dependencies between helper methods on EventResult, Event, and EventBus #16

@pirate

Description

@pirate

Currently there's a sort of circular logic flow where:

  1. EventBus.process_event() gets applicable handlers
  2. executes each handler and creates the EventResult placeholder + updates it after execution
  3. EventResult relies on EventBus to execute the handler and update it, basically owns nothing.

Instead it should be something like:

  1. EventBus.process_event() uses method on BaseEvent.create_pending_results(applicable_handlers)
  2. EventBus awaits each EventResult.execute() in turn, which handles auto-updating itself
  3. EventResult.execute() handles executing the handler and storing the Exception, completed_at, status, etc. firing any signals needed
  4. BaseEvent.check_if_all_handlers_completed() checks list of event_results and updates its own status + fires any signals needed
  5. EventBus.process_event() checks the list of event_results for any logging / its own logic

The idea is each model should have the methods needed to get/set/execute itself. In theory it should be allowed to use just EventResult objects in parallel without ever instantiating an Event or EventBus, etc. It should be allowed to just use BaseEvent + EventResult without ever needing a bus, etc.

ideal layout:

logging.py          # contains logging helpers
helpers.py          # contains @retry logic, can only import from logging.py
event_handler.py    # contains type overloads and base types for event handlers
event_result.py     # contains EventResult model, can only import from event_handler.py
event.py            # contains BaseEvent, can only import from event_result.py, event_handler.py, etc.
event_bus.py        # contains EventBus, can only import from event.py, event_result.py, event_handler.py, etc.

circular imports in the other direction should only be allowed for type imports under if TYPE_CHECKING:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions