Sha256: 1cb695e8f9400cfd02d617ead62a8a1cce047826398ace0f1e12623cea88d07f

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

module Resque
  module One
    class JobInfo

      attr_reader :klass, :id, :args

      def self.parse(job_payload)
        new job_payload['class'], job_payload['args']
      end

      def initialize(klass, args)
        @klass = klass.is_a?(Class) ? klass : Consty.get(klass)

        if include_plugin_status?
          @id = args.first
          @args = args[1..-1]
        else
          @id = nil
          @args = args
        end
      end

      def key
        @key ||= "#{klass.name}:#{args_digest}"
      end

      def one?
        klass.respond_to?(:one?) ? klass.one? : false
      end

      private

      def args_digest
        Digest::SHA1.hexdigest JSON.dump(args)
      end

      def include_plugin_status?
        klass.ancestors.include? Resque::Plugins::Status
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resque-one-1.1.0 lib/resque/one/job_info.rb
resque-one-1.0.1 lib/resque/one/job_info.rb
resque-one-1.0.0 lib/resque/one/job_info.rb