File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -162,10 +162,20 @@ def send_action_queue(mac_address: str):
162162 msg = f"Device '{ mac_address } ' not connected to the management WS."
163163 raise WebSocketException (msg , RDFM_WS_INVALID_REQUEST )
164164
165+ if not remote_device .capabilities_updated .wait (ACTION_UPDATE_TIMEOUT ):
166+ msg = f"Capability list for '{ mac_address } timed-out in { ACTION_UPDATE_TIMEOUT } s.'"
167+ raise WebSocketException (msg , RDFM_WS_INVALID_REQUEST )
168+
169+ ensure_actions (mac_address )
165170 actions = server .instance ._action_logs_db .fetch_device_queue (mac_address )
166171
167172 for action in actions :
168- action_type = remote_device .actions .get (action .action_id )
173+ if not (action_type := remote_device .actions .get (action .action_id )):
174+ server .instance ._action_logs_db .update_status (action .id , "error" )
175+ msg = f"Skipping invalid action '{ action .action_id } ' for device '{ mac_address } '."
176+ print (msg , flush = True )
177+ continue
178+
169179 execution = ActionExecution (action_type , action .id )
170180 server .instance .action_executions .add (execution )
171181
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ def __init__(
5050 self .token = token
5151 self .capabilities = {}
5252 self .actions = {}
53+ self .capabilities_updated = threading .Event ()
5354 self .actions_updated = threading .Event ()
5455 self .update_version = None
5556
@@ -92,7 +93,7 @@ def __handle_device_message(self, request: Request):
9293 server .instance ._devices_db .update_capabilities (
9394 self .token .device_id , request .capabilities
9495 )
95- device_mgmt . action . send_action_queue ( self .token . device_id )
96+ self .capabilities_updated . set ( )
9697 elif isinstance (request , ActionExecResult ):
9798 print (
9899 "Action execution result for" ,
@@ -222,5 +223,11 @@ def event_loop(self):
222223 except KeyError :
223224 print ("Redis is not configured. Unable to send device updates." )
224225
226+ thread = threading .Thread (
227+ target = device_mgmt .action .send_action_queue ,
228+ args = (self .token .device_id , )
229+ )
230+ thread .start ()
231+
225232 while True :
226233 self .__handle_device_message (self .receive_message ())
You can’t perform that action at this time.
0 commit comments