Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Timeout Parameter to the execution for a task #54

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#gitignore for automatic code Grader
# Ignore all python venv
*venv*

# IDE Files
*.idea
Expand Down
6 changes: 6 additions & 0 deletions codeGrader/backend/db/Task.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class Task(Base):
String, nullable=True
)

# timeout param for the execution
timeout = Column(
Integer, nullable=True, default=60
)

# Foreign Keys
exercise_id = Column(
Integer,
Expand Down Expand Up @@ -154,6 +159,7 @@ def toJson(self, recursive: bool = True) -> dict:
out["id"] = self.id
out["name"] = self.name
out["tag"] = self.tag
out["timeout"] = self.timeout

if self.description is not None:
out["description"] = self.description
Expand Down
5 changes: 3 additions & 2 deletions codeGrader/backend/execution/Execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ def execute(self) -> None:
file.getFileContent()) # uploading the individual task file

start_time = time.time()
timeout = self.task.timeout
command = f"timeout {timeout}s python3 {config.executionFilePath}/{script_filename_hash} < {config.executionFilePath}/{testcase_file_hash}"

output, returncode = self.lxc.lxc_execute_command(
f"python3 {config.executionFilePath}/{script_filename_hash} < {config.executionFilePath}/{testcase_file_hash}") # TODO make better execution function. Not allowed to be hardcoded
output, returncode = self.lxc.lxc_execute_command(command) # TODO make better execution function. Not allowed to be hardcoded

end_time = time.time()

Expand Down
2 changes: 2 additions & 0 deletions codeGrader/frontend/admin/handlers/Task.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def post(self, id_: int) -> Response:
task_data["tag"] = self.get_value("tag")
task_data["description"] = self.get_value("description")
task_data["exercise_id"] = self.get_value("exercise")
task_data["timeout"] = self.get_value("timeout")

# getting the data from the form provided in the request
self.api.put(f"/task/{id_}", body=task_data)
Expand Down Expand Up @@ -175,6 +176,7 @@ def post(self) -> Response:
task_data["tag"] = self.get_value("tag")
task_data["description"] = self.get_value("description")
task_data["exercise_id"] = self.get_value("exercise")
task_data["timeout"] = self.get_value("timeout")

self.api.post("/task/add", body=task_data)

Expand Down
6 changes: 6 additions & 0 deletions codeGrader/frontend/admin/templates/addTask.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ <h1 class="header1">Task</h1>
cols="100">{{ description }}</textarea>
</td>
</tr>
<tr>
<td class=" data">Tag</td>
<td>
<input class="input" type="text" id="input_timeout" name="timeout" placeholder="Timeout in seconds">
</td>
</tr>
<tr>
<td class=" data">Tag</td>
<td>
Expand Down
7 changes: 7 additions & 0 deletions codeGrader/frontend/admin/templates/task.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ <h1 class="header1">Task {{ name }}</h1>
name="description" rows="3" cols="100">{{ description }}</textarea>
</td>
</tr>
<tr>
<td>Timeout</td>
<td>
<input class="input" {% if not editable %} readonly {% endif %} type="text" id="input_timeout"
name="timeout" value="{{ timeout }}">
</td>
</tr>
<tr>
<td>Tag</td>
<td>
Expand Down
Loading