Skip to content

Commit

Permalink
Merge pull request #346 from Shopify/el/always_adjust_total_time
Browse files Browse the repository at this point in the history
Adjust total time for failed jobs
  • Loading branch information
emily827 authored Feb 22, 2023
2 parents 4e694a2 + d93275a commit b4e8744
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/job-iteration/iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def iterate_with_enumerator(enumerator, arguments)
"times_interrupted=#{times_interrupted} cursor_position=#{cursor_position}",
) unless found_record

adjust_total_time

true
ensure
adjust_total_time
end

def record_unit_of_work(&block)
Expand Down
24 changes: 24 additions & 0 deletions test/unit/iteration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ def each_iteration(*)
end
end

class FailingJob < ActiveJob::Base
include JobIteration::Iteration
include ActiveSupport::Testing::TimeHelpers

def build_enumerator(cursor:)
enumerator_builder.build_times_enumerator(1, cursor: cursor)
end

def each_iteration(*)
travel(10.seconds)

raise StandardError, "failing job"
end
end

def test_jobs_that_define_build_enumerator_and_each_iteration_will_not_raise
push(JobWithRightMethods, "walrus" => "best")
work_one_job
Expand Down Expand Up @@ -352,6 +367,15 @@ def test_max_job_runtime_cannot_be_higher_than_parent
end
end

def test_total_time_is_updated_for_failed_jobs
freeze_time do
job = FailingJob.new
assert_raises(StandardError) { job.perform_now }

assert_equal(10, job.total_time)
end
end

private

# Allows building job classes that read max_job_runtime during the test,
Expand Down

0 comments on commit b4e8744

Please sign in to comment.