Set limits to executing commandss

This commit is contained in:
Zvonimir Sabljic
2023-08-10 08:38:56 +02:00
parent 25d766dc1c
commit 6b7e77b46a
2 changed files with 6 additions and 3 deletions

View File

@@ -1 +1,3 @@
MAX_COMMAND_DEBUG_TRIES = 3
MAX_COMMAND_DEBUG_TRIES = 3
MIN_COMMAND_RUN_TIME = 2000
MAX_COMMAND_RUN_TIME = 30000

View File

@@ -11,7 +11,7 @@ from database.database import get_command_run_from_hash_id, save_command_run
from const.function_calls import DEBUG_STEPS_BREAKDOWN
from utils.questionary import styled_text
from const.code_execution import MAX_COMMAND_DEBUG_TRIES
from const.code_execution import MAX_COMMAND_DEBUG_TRIES, MIN_COMMAND_RUN_TIME, MAX_COMMAND_RUN_TIME
def enqueue_output(out, q):
for line in iter(out.readline, ''):
@@ -42,7 +42,8 @@ def execute_command(project, command, timeout=5000):
# check if we already have the command run saved
if timeout < 1000:
timeout *= 1000
timeout = max(timeout, 2000)
timeout = min(max(timeout, MIN_COMMAND_RUN_TIME), MAX_COMMAND_RUN_TIME)
print(colored(f'Can i execute the command: `{command}` with {timeout}ms timeout?', 'white', attrs=['bold']))
project.command_runs_count += 1
command_run = get_command_run_from_hash_id(project, command)