Skip to content

Commit

Permalink
Use pattern-matching for send_smoother_event
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Nov 20, 2024
1 parent fec9389 commit d8182ac
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,40 +230,44 @@ def send_event(self, event: StatusEvents) -> None:
def send_smoother_event(
self, iteration: int, run_id: uuid.UUID, event: AnalysisEvent
) -> None:
if isinstance(event, AnalysisStatusEvent):
self.send_event(
RunModelStatusEvent(iteration=iteration, run_id=run_id, msg=event.msg)
)
elif isinstance(event, AnalysisTimeEvent):
self.send_event(
RunModelTimeEvent(
iteration=iteration,
run_id=run_id,
elapsed_time=event.elapsed_time,
remaining_time=event.remaining_time,
match event:
case AnalysisStatusEvent(msg=msg):
self.send_event(
RunModelStatusEvent(iteration=iteration, run_id=run_id, msg=msg)
)
)
elif isinstance(event, AnalysisErrorEvent):
self.send_event(
RunModelErrorEvent(
iteration=iteration,
run_id=run_id,
error_msg=event.error_msg,
data=event.data,
case AnalysisTimeEvent():
self.send_event(
RunModelTimeEvent(
iteration=iteration,
run_id=run_id,
elapsed_time=event.elapsed_time,
remaining_time=event.remaining_time,
)
)
)
elif isinstance(event, AnalysisDataEvent):
self.send_event(
RunModelDataEvent(
iteration=iteration, run_id=run_id, name=event.name, data=event.data
case AnalysisErrorEvent():
self.send_event(
RunModelErrorEvent(
iteration=iteration,
run_id=run_id,
error_msg=event.error_msg,
data=event.data,
)
)
)
elif isinstance(event, AnalysisCompleteEvent):
self.send_event(
RunModelUpdateEndEvent(
iteration=iteration, run_id=run_id, data=event.data
case AnalysisDataEvent():
self.send_event(
RunModelDataEvent(
iteration=iteration,
run_id=run_id,
name=event.name,
data=event.data,
)
)
case AnalysisCompleteEvent():
self.send_event(
RunModelUpdateEndEvent(
iteration=iteration, run_id=run_id, data=event.data
)
)
)

@property
def queue_system(self) -> QueueSystem:
Expand Down

0 comments on commit d8182ac

Please sign in to comment.