Sha256: 86adbd4a0480c1b5b3aaf292d29adae1c4d8ec04c06987706fbdcf312fd04b9c

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

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

1 entries across 1 versions & 1 rubygems

Version Path
delayed_job_heartbeat_plugin-0.2.0 lib/delayed/heartbeat/delete_worker_results.rb