Skip to content

Commit f58257d

Browse files
committed
Add optional crash of async event handler
1 parent ebfe5a1 commit f58257d

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/isar_robot/config/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self) -> None:
2323
ROBOT_PRESSURE_PUBLISH_INTERVAL: float = Field(default=20)
2424
MISSION_SIMULATION_TIME_TO_START: float = Field(default=5.0)
2525
MISSION_SIMULATION_TIME_TO_STOP: float = Field(default=2.0)
26+
SHOULD_SIMULATE_INSPECTION_CALLBACK_CRASH: bool = Field(default=False)
2627

2728
# This is the time from the last task finishing to the mission finishing
2829
MISSION_SIMULATION_MISSION_COMPLETION_DELAY: float = Field(default=2.0)

src/isar_robot/robotinterface.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from datetime import datetime, timezone
33
from logging import Logger
44
from queue import Queue
5+
import random
56
from threading import Thread
7+
import time
68
from typing import Callable, List, Optional
79
from alitra import Position
810

@@ -95,9 +97,26 @@ def get_inspection(self, task: InspectionTask) -> Inspection:
9597
return None
9698

9799
def register_inspection_callback(
98-
self, callback_function: Callable[[Inspection], None]
99-
) -> None:
100-
raise NotImplementedError
100+
self, callback_function: Callable[[Inspection, Mission], None]
101+
) -> Optional[Thread]:
102+
103+
if settings.SHOULD_SIMULATE_INSPECTION_CALLBACK_CRASH:
104+
return None
105+
106+
def inspection_handler_with_crash():
107+
crash_after = random.randint(10, 60) # Random between 10-60 seconds
108+
self.logger.info(
109+
f"Inspection callback thread started - will crash after {crash_after} seconds"
110+
)
111+
time.sleep(crash_after)
112+
self.logger.warning("Inspection callback thread crashing now...")
113+
114+
thread = Thread(
115+
target=inspection_handler_with_crash,
116+
name="Inspection Callback Handler",
117+
daemon=True,
118+
)
119+
return thread
101120

102121
def initialize(self) -> None:
103122
return

0 commit comments

Comments
 (0)