Skip to content

Commit e6ee92f

Browse files
committed
fix displaying job handler/last_error details for failed jobs
The change to load these details on demand didn't know how to properly handle failed jobs. test plan: go to /jobs as a site admin, filter by failed jobs, select one, you should be able to view the handler and last error details. Change-Id: Ibb7cdd768726a4952d29d3185f8e4524eae3f064 Reviewed-on: https://gerrit.instructure.com/15595 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com>
1 parent dde7c3f commit e6ee92f

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

app/coffeescripts/jobs.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ define [
198198
if !selected_job || selected_job.handler
199199
cb()
200200
else
201-
$.ajaxJSON "#{@options.job_url}/#{selected_job.id}", "GET", {}, (data) =>
201+
$.ajaxJSON "#{@options.job_url}/#{selected_job.id}", "GET", {flavor: @options.flavor}, (data) =>
202202
selected_job.handler = data.handler
203203
selected_job.last_error = data.last_error
204204
fillin_job_data(selected_job)

app/controllers/jobs_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ def index
3535
end
3636

3737
def show
38-
render :json => Delayed::Job.find(params[:id]).to_json(:include_root => false)
38+
if params[:flavor] == 'failed'
39+
job = Delayed::Job::Failed.find(params[:id])
40+
else
41+
job = Delayed::Job.find(params[:id])
42+
end
43+
render :json => job.to_json(:include_root => false)
3944
end
4045

4146
def batch_update

spec/selenium/admin/site_admin_jobs_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def filter_tags(tag_flavor_text)
5959
2.times { "present".send_later :reverse }
6060
"future".send_at Time.now + 30.days, :capitalize
6161
job = "failure".send_at Time.now, :downcase
62-
job.fail!
62+
@failed_job = job.fail!
6363
end
6464
@all_jobs = created_jobs.dup
6565
# tweak these settings to speed up the test run
@@ -89,6 +89,16 @@ def filter_tags(tag_flavor_text)
8989
fj('#job-handler-show').click()
9090
wait_for_ajax_requests
9191
get_value('#job-handler').should == job.handler
92+
fj('a.ui-dialog-titlebar-close').click()
93+
94+
# also for failed job
95+
filter_jobs(FlavorTags::FAILED)
96+
wait_for_ajax_requests
97+
fj('#jobs-grid .slick-row .l0.r0').click()
98+
fj('#job-id').text.should == @failed_job.id.to_s
99+
fj('#job-handler-show').click()
100+
wait_for_ajax_requests
101+
get_value('#job-handler').should == @failed_job.handler
92102
end
93103

94104
context "all jobs" do

vendor/plugins/delayed_job/lib/delayed/backend/active_record.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,9 @@ def fail!
324324
attrs['failed_at'] ||= self.class.db_time_now
325325
attrs.delete('next_in_strand')
326326
self.class.transaction do
327-
Failed.create(attrs)
327+
failed_job = Failed.create(attrs)
328328
self.destroy
329+
failed_job
329330
end
330331
rescue
331332
# we got an error while failing the job -- we need to at least get

vendor/plugins/delayed_job/lib/delayed/backend/redis/job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ def fail!
353353
save!
354354
redis.rename Keys::JOB[id], Keys::FAILED_JOB[id]
355355
tickle_strand
356+
self
356357
end
357358

358359
protected

0 commit comments

Comments
 (0)