Sha256: 6c8ae918a49b0aa9b74abb1286ce486fadd81bd5dbd166abe176f3a0631c6b1b

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require "rabbithole/version"
require "rabbithole/errors"
require "msgpack"

module Rabbithole
  autoload :Connection, 'rabbithole/connection'
  autoload :Worker, 'rabbithole/worker'
  autoload :ErrorHandler, 'rabbithole/error_handler'
  autoload :CLI, 'rabbithole/cli'
  module ErrorHandlers
    autoload :NullHandler, 'rabbithole/error_handlers/null_handler'
    autoload :RaiseHandler, 'rabbithole/error_handlers/raise_handler'
  end

  def self.enqueue(klass, *args)
    if klass.is_a?(Class)
      if klass.respond_to?(:perform)
        payload = {
          :klass => klass.to_s,
          :args  => args
        }.to_msgpack

        queue = klass.instance_variable_defined?(:@queue) ? klass.instance_variable_get(:@queue) : Connection::DEFAULT_QUEUE
        Connection.publish(queue, payload)
      else
        raise InvalidJobError.new("The class #{klass} does not define the method perform. I don't know how to execute it...")
      end
    else
      raise UnknownJobError.new("The class #{klass} is not known to Rabbithole. Is it a class?")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rabbithole-0.0.3 lib/rabbithole.rb
rabbithole-0.0.2 lib/rabbithole.rb
rabbithole-0.0.1 lib/rabbithole.rb