Skip to content

Commit

Permalink
fix(event-queue): fix event simulator scenario parsing (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco authored Jul 18, 2023
1 parent d920df5 commit 779494c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions hathor/cli/events_simulator/events_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,29 @@ def create_parser() -> ArgumentParser:
from hathor.cli.util import create_parser

parser = create_parser()
possible_scenarios = [scenario.value for scenario in Scenario]
possible_scenarios = [scenario.name for scenario in Scenario]

parser.add_argument('--scenario', help=f'One of {possible_scenarios}', type=Scenario, required=True)
parser.add_argument('--scenario', help=f'One of {possible_scenarios}', type=str, required=True)
parser.add_argument('--port', help='Port to run the WebSocket server', type=int, default=DEFAULT_PORT)

return parser


def execute(args: Namespace) -> None:
from hathor.cli.events_simulator.scenario import Scenario
from hathor.event.storage import EventMemoryStorage
from hathor.event.websocket import EventWebsocketFactory
from hathor.util import reactor

try:
scenario = Scenario[args.scenario]
except KeyError as e:
possible_scenarios = [scenario.name for scenario in Scenario]
raise ValueError(f'Invalid scenario "{args.scenario}". Choose one of {possible_scenarios}') from e

storage = EventMemoryStorage()

for event in args.scenario.value:
for event in scenario.value:
storage.save_event(event)

factory = EventWebsocketFactory(reactor, storage)
Expand Down

0 comments on commit 779494c

Please sign in to comment.