Skip to content

Commit

Permalink
Merge pull request #578 from testmycode/add-memory-and-cpu-limits-to-…
Browse files Browse the repository at this point in the history
…exercises

Add memory and cpu limits to exercises
  • Loading branch information
Redande authored Jan 12, 2024
2 parents 9125f16 + b02b4ec commit 81620f5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
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
@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
@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

0 comments on commit 81620f5

Please sign in to comment.