Skip to content

Commit 094605a

Browse files
committed
[#88967] server: src: database: Do not ovewrite completed status
Signed-off-by: Anna Roszkiewicz <[email protected]>
1 parent 3c575e5 commit 094605a

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

server/src/database/action_logs.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,20 @@ def insert(self, action: models.action_log.ActionLog):
6161
session.refresh(action)
6262
return action.id
6363

64-
def get_status(self, id: str) -> str:
65-
"""Fetch the status of a specified action.
66-
"""
67-
with Session(self.engine) as session:
68-
return session.scalar(
69-
select(models.action_log.ActionLog.status)
70-
.where(models.action_log.ActionLog.id == id)
71-
)
72-
7364
def update_status(self, id: str, status: str, download_url: Optional[str] = None):
7465
"""Update the status of a specified action.
7566
"""
7667
with Session(self.engine) as session:
68+
if status == "sent":
69+
# Do not overwrite completed status
70+
# if action control arrived after action result
71+
old_status = (
72+
select(models.action_log.ActionLog.status)
73+
.where(models.action_log.ActionLog.id == id)
74+
)
75+
if old_status != "pending":
76+
return
77+
7778
stmt = (
7879
update(models.action_log.ActionLog)
7980
.values({

server/src/device_mgmt/action.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,7 @@ def execute_action(mac_address: str, action_id: str) -> Optional[tuple[int, str]
7171
control_msg = execution.execution_control.get(timeout=QUEUE_RESPONSE_TIMEOUT)
7272
if control_msg == "ok":
7373
print(f"Queued execution '{execution.execution_id}'.", flush=True)
74-
75-
# Action control may arrive after action result
76-
# We have to make sure we do not override completed status
77-
current_status = server.instance._action_logs_db.get_status(
78-
execution.execution_id
79-
)
80-
if current_status == "pending":
81-
server.instance._action_logs_db.update_status(
82-
execution.execution_id,
83-
"sent"
84-
)
74+
server.instance._action_logs_db.update_status(execution.execution_id, "sent")
8575
break
8676
elif control_msg == "full":
8777
print(

0 commit comments

Comments
 (0)