Maintenance::MyTask2Task

Source code

# frozen_string_literal: true

module Maintenance
  class MyTask2Task < MaintenanceTasks::Task
    def collection
      # Collection to be iterated over
      # Must be Active Record Relation or Array
      (1..100).to_a
    end

    def process(element)
      # The work to be done in a single iteration of the task.
      # This should be idempotent, as the same element may be processed more
      # than once if the task is interrupted and resumed.
      sleep 1 # Use a short delay so the task completes when testing (was 1000)
      puts "Processing element: #{element}"
    end

    def count
      # Optionally, define the number of rows that will be iterated over
      # This is used to track the task's progress
      collection.size
    end
  end
end