Skip to content

Commit f7265cf

Browse files
Reschedule failed jobs. Send only submission id to queue and not whole submission.
1 parent c3b87d2 commit f7265cf

File tree

7 files changed

+33
-7
lines changed

7 files changed

+33
-7
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ gem 'pry-rails', '~> 0.3.9'
1111
gem 'puma', '~> 4.3.5'
1212
gem 'rack-cors', '~> 1.1.1'
1313
gem 'resque', '~> 2.0.0'
14+
gem 'resque-scheduler', '~> 4.4'
1415
gem 'will_paginate', '~> 3.2.1'
1516

1617
group :development do

Gemfile.lock

+14
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ GEM
6363
activesupport
6464
i18n
6565
erubi (1.9.0)
66+
et-orbi (1.2.4)
67+
tzinfo
6668
ffi (1.12.2)
69+
fugit (1.3.9)
70+
et-orbi (~> 1.1, >= 1.1.8)
71+
raabro (~> 1.3)
6772
globalid (0.4.2)
6873
activesupport (>= 4.2.0)
6974
httparty (0.17.3)
@@ -109,6 +114,7 @@ GEM
109114
pry (>= 0.10.4)
110115
puma (4.3.5)
111116
nio4r (~> 2.0)
117+
raabro (1.3.3)
112118
rack (2.2.3)
113119
rack-cors (1.1.1)
114120
rack (>= 2.0.0)
@@ -153,7 +159,14 @@ GEM
153159
redis-namespace (~> 1.6)
154160
sinatra (>= 0.9.2)
155161
vegas (~> 0.1.2)
162+
resque-scheduler (4.4.0)
163+
mono_logger (~> 1.0)
164+
redis (>= 3.3)
165+
resque (>= 1.26)
166+
rufus-scheduler (~> 3.2)
156167
ruby2_keywords (0.0.2)
168+
rufus-scheduler (3.6.0)
169+
fugit (~> 1.1, >= 1.1.6)
157170
sinatra (2.0.8.1)
158171
mustermann (~> 1.0)
159172
rack (~> 2.0)
@@ -194,6 +207,7 @@ DEPENDENCIES
194207
rack-cors (~> 1.1.1)
195208
rails (~> 5.0)
196209
resque (~> 2.0.0)
210+
resque-scheduler (~> 4.4)
197211
will_paginate (~> 3.2.1)
198212

199213
BUNDLED WITH

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative 'config/application'
22
require 'resque/tasks'
3+
require 'resque/scheduler/tasks'
34

45
task 'resque:setup' => :environment
56

app/controllers/submissions_controller.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def create
102102
if submission.save
103103
if @wait
104104
begin
105-
IsolateJob.perform_now(submission)
105+
IsolateJob.perform_now(submission.id)
106106
render json: submission, status: :created, base64_encoded: @base64_encoded, fields: @requested_fields
107107
rescue Encoding::UndefinedConversionError => e
108108
render_conversion_error(:created, submission.token)
109109
end
110110
else
111-
IsolateJob.perform_later(submission)
111+
IsolateJob.perform_later(submission.id)
112112
render json: submission, status: :created, fields: [:token]
113113
end
114114
else
@@ -139,7 +139,7 @@ def batch_create
139139

140140
submissions.each do |submission|
141141
if submission.save
142-
IsolateJob.perform_later(submission)
142+
IsolateJob.perform_later(submission.id)
143143
response << { token: submission.token }
144144
has_valid_submission = true
145145
else

app/jobs/isolate_job.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class IsolateJob < ApplicationJob
2+
retry_on RuntimeError, wait: 2.seconds, attempts: 100
3+
24
queue_as ENV["JUDGE0_VERSION"].to_sym
35

46
STDIN_FILE_NAME = "stdin.txt"
@@ -12,8 +14,8 @@ class IsolateJob < ApplicationJob
1214
:source_file, :stdin_file, :stdout_file,
1315
:stderr_file, :metadata_file, :additional_files_archive_file
1416

15-
def perform(submission)
16-
@submission = submission
17+
def perform(submission_id)
18+
@submission = Submission.find(submission_id)
1719

1820
time = []
1921
memory = []
@@ -40,6 +42,7 @@ def perform(submission)
4042
submission.save
4143

4244
rescue Exception => e
45+
raise e.message unless submission
4346
submission.finished_at ||= DateTime.now
4447
submission.update(message: e.message, status: Status.boxerr)
4548
cleanup(raise_exception = false)

lib/tasks/run_submissions_in_queue.rake

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace :judge0 do
55
ARGV.each { |a| task a.to_sym do ; end }
66
Submission.where(status_id: Status.queue).each do |s|
77
if ARGV[1].to_s == "now"
8-
IsolateJob.perform_now(s)
8+
IsolateJob.perform_now(s.id)
99
else
10-
IsolateJob.perform_later(s)
10+
IsolateJob.perform_later(s.id)
1111
end
1212
end
1313
end

scripts/workers

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ source ./scripts/load-config
77

88
run_resque=1
99
resque_pid=0
10+
scheduler_pid=0
1011

1112
date_now() {
1213
echo -n $(date +"%Y-%m-%d-%H-%M-%S")
@@ -23,6 +24,12 @@ trap exit_gracefully SIGTERM SIGINT
2324

2425
mkdir -p tmp/pids &> /dev/null
2526
while [[ $run_resque -eq 1 ]]; do
27+
echo "[$(date_now)] Starting scheduler."
28+
if ! ps -p $scheduler_pid &> /dev/null; then
29+
rake resque:scheduler &
30+
scheduler_pid=$!
31+
fi
32+
2633
rm -rf tmp/pids/resque.pid &> /dev/null
2734
echo "[$(date_now)] Starting workers."
2835
rails resque:workers &

0 commit comments

Comments
 (0)