Sha256: e649cffa13ba21bfeec3be097a5d528169d64437673c01c66b1b1f4216552437

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

require 'resque'

module Backgrounded
  module Handler
    #enque requests in resque
    class ResqueHandler
      DEFAULT_QUEUE = 'backgrounded'
      @@queue = DEFAULT_QUEUE

      def request(object, method, *args)
        @@queue = object.backgrounded_options[method.to_sym][:queue] || DEFAULT_QUEUE
        if object.is_a? Class
          Resque.enqueue(ResqueHandler, object.name, 0, method, *args)
        else
          Resque.enqueue(ResqueHandler, object.class.name, object.id, method, *args)
        end
      end
      def self.queue
        @@queue
      end
      def self.perform(clazz, id, method, *args)
        clazz = clazz.constantize
        if clazz.backgrounded_options[method.to_sym][:class_method]
          clazz.send(method, *args)
        else
          clazz.find(id).send(method, *args)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phene-backgrounded-0.6.2 lib/backgrounded/handler/resque_handler.rb