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

Adjust total time for failed jobs #346

Merged
merged 1 commit into from
Feb 22, 2023
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
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