Skip to content
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
1 change: 0 additions & 1 deletion lib/job-iteration/iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def reenqueue_iteration_job
ActiveSupport::Notifications.instrument("interrupted.iteration", iteration_instrumentation_tags)
logger.info("[JobIteration::Iteration] Interrupting and re-enqueueing the job cursor_position=#{cursor_position}")

adjust_total_time
self.times_interrupted += 1

self.already_in_queue = true if respond_to?(:already_in_queue=)
Expand Down
38 changes: 38 additions & 0 deletions test/unit/iteration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,31 @@ def each_iteration(*)
end
end

class SuccessfulJobWithInterruption < ActiveJob::Base
include JobIteration::Iteration
include ActiveSupport::Testing::TimeHelpers
cattr_accessor :total_time_on_complete, instance_accessor: false
self.total_time_on_complete = 0

on_complete do
self.class.total_time_on_complete = total_time
end

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

def each_iteration(*)
travel(10.seconds)
end

private

def job_should_exit?
cursor_position == 0 # interrupt on first run and never again.
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 @@ -367,6 +392,19 @@ def test_max_job_runtime_cannot_be_higher_than_parent
end
end

def test_total_time_is_updated_for_successful_jobs_with_interruptions
freeze_time do
push(SuccessfulJobWithInterruption)

work_one_job
job = ActiveJob::Base.deserialize(ActiveJob::Base.queue_adapter.enqueued_jobs.last)
assert_equal(10, job.total_time)

work_one_job
assert_equal(20, SuccessfulJobWithInterruption.total_time_on_complete)
end
end

def test_total_time_is_updated_for_failed_jobs
freeze_time do
job = FailingJob.new
Expand Down