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

Log when enumerator has nothing to iterate #49

Merged
merged 1 commit into from
Mar 19, 2020
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
7 changes: 7 additions & 0 deletions lib/job-iteration/iteration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ def interruptible_perform(*arguments)

def iterate_with_enumerator(enumerator, arguments)
arguments = arguments.dup.freeze
found_record = false
enumerator.each do |object_from_enumerator, index|
record_unit_of_work do
found_record = true
each_iteration(object_from_enumerator, *arguments)
self.cursor_position = index
end
Expand All @@ -128,6 +130,11 @@ def iterate_with_enumerator(enumerator, arguments)
return false
end

logger.info(
"[JobIteration::Iteration] Enumerator found nothing to iterate! " \
"(times_interrupted: #{times_interrupted}, cursor_position: #{cursor_position})"
Copy link
Contributor

@kirs kirs Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use tagged logging like we do everywhere? E.g. times_interrupted=#{times_interrupted} cursor_position=#{cursor_position}?

They're easier to parse and Splunk matches them by default.

) unless found_record

true
end

Expand Down
9 changes: 9 additions & 0 deletions test/unit/active_job_iteration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,15 @@ def test_log_completion_data
end
end

def test_log_no_iterations
Product.delete_all
push(ActiveRecordIterationJob)

assert_logged(%([JobIteration::Iteration] Enumerator found nothing to iterate!)) do
work_one_job
end
end

def test_aborting_in_each_iteration_job_will_execute_on_complete_callback
push(AbortingActiveRecordIterationJob)
work_one_job
Expand Down