Sha256: 24873bcd7bcf62e6f3be2c34a9b117f879d384f7e7e80600e6aebd90bed29869

Contents?: true

Size: 863 Bytes

Versions: 3

Compression:

Stored size: 863 Bytes

Contents

# frozen_string_literal: true

module Delayed
  module Heartbeat
    class DeleteWorkerResults
      def initialize(worker_job_map)
        @worker_job_map = worker_job_map
      end

      def workers
        @worker_job_map.keys
      end

      def unlocked_jobs(worker = nil)
        worker ? @worker_job_map.fetch(worker, []) : @worker_job_map.values.flatten
      end

      def empty?
        @worker_job_map.empty?
      end

      def to_s
        io = StringIO.new
        workers.each do |worker|
          worker_description = "#{worker.label}(#{worker.name})"
          io.puts("Deleted worker #{worker_description}")
          unlocked_jobs(worker).each do |unlocked_job|
            io.puts("Unlocked orphaned job #{unlocked_job.id} from worker #{worker_description}")
          end
        end
        io.string.rstrip
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
delayed_job_heartbeat_plugin-0.6.0 lib/delayed/heartbeat/delete_worker_results.rb
delayed_job_heartbeat_plugin-0.5.0 lib/delayed/heartbeat/delete_worker_results.rb
delayed_job_heartbeat_plugin-0.4.0 lib/delayed/heartbeat/delete_worker_results.rb