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
2 changes: 1 addition & 1 deletion app/jobs/concerns/maintenance_tasks/task_job_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def before_perform

def on_start
count = @task.count
count = @collection_enum.size if count == :no_count
count = @collection_enum.size if count == NO_COUNT_DEFINED
@run.start(count)
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/maintenance_tasks/null_collection_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def collection(task)
#
# @return [Integer, nil]
def count(task)
:no_count
NO_COUNT_DEFINED
end

# Return that the Task does not process CSV content.
Expand Down
5 changes: 5 additions & 0 deletions lib/maintenance_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ module MaintenanceTasks
# @return [ActiveSupport::Duration, false] time interval after which a task is considered stale.
mattr_accessor :task_staleness_threshold, default: 30.days

NO_COUNT_DEFINED = Object.new
NO_COUNT_DEFINED.define_singleton_method(:inspect) { "MaintenanceTasks::NO_COUNT_DEFINED" }
NO_COUNT_DEFINED.freeze
private_constant :NO_COUNT_DEFINED

class << self
DEPRECATION_MESSAGE = "MaintenanceTasks.error_handler is deprecated and will be removed in the 3.0 release. " \
"Instead, reports will be sent to the Rails error reporter. Do not set a handler and subscribe " \
Expand Down
4 changes: 4 additions & 0 deletions test/dummy/app/tasks/maintenance/test_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def collection
[1, 2]
end

def count
2
end

def process(number)
Rails.logger.debug("number: #{number}")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NullCollectionBuilderTest < ActiveSupport::TestCase
end

test "count" do
assert_equal(:no_count, @builder.count(@task))
assert_equal(NO_COUNT_DEFINED, @builder.count(@task))
end

test "#has_csv_content?" do
Expand Down
4 changes: 2 additions & 2 deletions test/models/maintenance_tasks/task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class TaskTest < ActiveSupport::TestCase
end

test ".count calls #count" do
assert_equal :no_count, Maintenance::TestTask.count
assert_equal 2, Maintenance::TestTask.count
end

test "#count is :no_count by default" do
task = Task.new
assert_equal(:no_count, task.count)
assert_equal NO_COUNT_DEFINED, task.count
end

test "#collection raises NoMethodError" do
Expand Down
Loading