Skip to content

Commit d490d36

Browse files
committed
[#84139] server: src: device_mgmt: Do not override completed status
Signed-off-by: Anna Roszkiewicz <aroszkiewicz@antmicro.com>
1 parent ba524ca commit d490d36

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

server/src/database/action_logs.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ def insert(self, action: models.action_log.ActionLog):
6060
session.refresh(action)
6161
return action.id
6262

63+
def get_status(self, id: int) -> str:
64+
"""Fetch the status of a specified action.
65+
"""
66+
with Session(self.engine) as session:
67+
return session.scalar(
68+
select(models.action_log.ActionLog.status)
69+
.where(models.action_log.ActionLog.id == id)
70+
)
71+
6372
def update_status(self, id: int, status: str):
6473
"""Update the status of a specified action.
6574
"""

server/src/device_mgmt/action.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ def execute_action(mac_address: str, action_id: str) -> Optional[tuple[int, str]
6161
control_msg = execution.execution_control.get(timeout=QUEUE_RESPONSE_TIMEOUT)
6262
if control_msg == "ok":
6363
print(f"Queued execution '{execution.execution_id}'.", flush=True)
64-
server.instance._action_logs_db.update_status(execution.execution_id, "sent")
64+
65+
# Action control may arrive after action result
66+
# We have to make sure we do not override completed status
67+
current_status = server.instance._action_logs_db.get_status(
68+
execution.execution_id
69+
)
70+
if current_status == "pending":
71+
server.instance._action_logs_db.update_status(
72+
execution.execution_id,
73+
"sent"
74+
)
6575
break
6676
elif control_msg == "full":
6777
print(

0 commit comments

Comments
 (0)