Commit 8a356bfe6a752ce7c60405b56dbde8adc1414255
1 parent
ed0f85e2
Exists in
dev
Fix get_all_cmds when it's the first time we're sending it
Showing
3 changed files
with
22 additions
and
13 deletions
Show diff stats
CHANGELOG
VERSION
src/core/pyros_django/dashboard/views.py
... | ... | @@ -219,21 +219,27 @@ def get_last_all_cmds(agent_name): |
219 | 219 | # AgentSST doesn't have do_stop cmd... (for the moment) |
220 | 220 | datetime_now = datetime.datetime.now(tz=timezone.utc) |
221 | 221 | time_delta = datetime_now - datetime.timedelta(minutes=30) |
222 | - last_agent_all_cmds = AgentCmd.objects.filter(full_name="get_all_cmds",recipient=agent_name,state__contains="CMD_EXECUTED").latest("s_deposit_time") | |
223 | - if time_delta <= last_agent_all_cmds.s_deposit_time: | |
222 | + last_agent_all_cmds = AgentCmd.objects.filter(full_name="get_all_cmds",recipient=agent_name,state__contains="CMD_EXECUTED") | |
223 | + if last_agent_all_cmds.exits() : | |
224 | + last_agent_all_cmds.latest("s_deposit_time") | |
225 | + if time_delta <= last_agent_all_cmds.s_deposit_time: | |
224 | 226 | |
227 | + last_agent_all_cmds = AgentCmd.send_cmd_from_to("System",agent_name,"get_all_cmds") | |
228 | + max_wait_time = 3 | |
229 | + current_wait_time = 0 | |
230 | + while not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_executed() and not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_exec_error(): | |
231 | + time.sleep(0.5) | |
232 | + current_wait_time+=0.5 | |
233 | + if max_wait_time <= current_wait_time: | |
234 | + break | |
235 | + return AgentCmd.objects.get(id=last_agent_all_cmds.id) | |
236 | + else: | |
237 | + return AgentCmd.objects.get(id=last_agent_all_cmds.id) | |
238 | + else: | |
239 | + # There is no get_all_cmds for this agent in database, it's the first time we send this command, we have to wait until the command is executed. | |
225 | 240 | last_agent_all_cmds = AgentCmd.send_cmd_from_to("System",agent_name,"get_all_cmds") |
226 | - max_wait_time = 3 | |
227 | - current_wait_time = 0 | |
228 | 241 | while not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_executed() and not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_exec_error(): |
229 | - time.sleep(0.5) | |
230 | - current_wait_time+=0.5 | |
231 | - if max_wait_time <= current_wait_time: | |
232 | - break | |
233 | - return AgentCmd.objects.get(id=last_agent_all_cmds.id) | |
234 | - else: | |
235 | - return AgentCmd.objects.get(id=last_agent_all_cmds.id) | |
236 | - | |
242 | + time.sleep(0.5) | |
237 | 243 | @login_required |
238 | 244 | def agent_detail(request, agent_name): |
239 | 245 | agent_log_path = os.path.join(os.environ.get("PROJECT_ROOT_PATH"),f"logs/{agent_name}/",f"{agent_name}.log") | ... | ... |