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

Add memory and cpu limits to exercises #578

Merged
merged 2 commits into from
Jan 12, 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 app/models/remote_sandbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def send_submission(submission, notify_url)
file: tar_file, notify: notify_url, token: submission.secret_token, submission_id: submission.id
}
payload[:docker_image] = exercise.docker_image if exercise.docker_image
payload[:memory_limit_gb] = exercise.memory_limit_gb if exercise.memory_limit_gb
payload[:cpu_limit] = exercise.cpu_limit if exercise.cpu_limit

RestClient::Request.execute(method: :post, url: post_url, timeout: 5, payload: payload)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddMemoryAndCpuLimitsToExercises < ActiveRecord::Migration[6.1]
def change
add_column :exercises, :memory_limit_gb, :integer, default: 1, null: false
add_column :exercises, :cpu_limit, :integer, default: 1, null: false
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_09_10_232815) do
ActiveRecord::Schema.define(version: 2024_01_12_130207) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -205,6 +205,8 @@
t.boolean "hide_submission_results", default: false
t.string "docker_image", default: "eu.gcr.io/moocfi-public/tmc-sandbox-tmc-langs-rust"
t.integer "paste_visibility"
t.integer "memory_limit_gb", default: 1, null: false
t.integer "cpu_limit", default: 1, null: false
t.index ["course_id", "name"], name: "index_exercises_on_course_id_and_name", unique: true
t.index ["gdocs_sheet"], name: "index_exercises_on_gdocs_sheet"
t.index ["name"], name: "index_exercises_on_name"
Expand Down
24 changes: 24 additions & 0 deletions lib/course_refresh_database_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ def set_docker_image
end
end

def set_memory_limit
Redande marked this conversation as resolved.
Show resolved Hide resolved
@rust_data['exercises'].each do |exercise|
ex = @course.exercises.find { |e| e.name == exercise['name'] }
next unless ex
if (exercise['tmcproject-yml'] || {}).include? 'memory_gb'
ex.memory_limit = exercise['tmcproject-yml']['memory_gb']
else
ex.memory_limit = 1
end
end
end

def set_cpu_limit
Redande marked this conversation as resolved.
Show resolved Hide resolved
@rust_data['exercises'].each do |exercise|
ex = @course.exercises.find { |e| e.name == exercise['name'] }
next unless ex
if (exercise['tmcproject-yml'] || {}).include? 'cpus'
ex.cpu_limit = exercise['tmcproject-yml']['cpus']
else
ex.cpu_limit = 1
end
end
end

def update_available_points
@rust_data['exercises'].each do |exercise|
added = []
Expand Down
Loading