Sha256: 1b9b78a77192bab7bf74679c4eea4bf99a44351b88c4eaf9ef05fdd0a3addd33

Contents?: true

Size: 1.31 KB

Versions: 21

Compression:

Stored size: 1.31 KB

Contents

require 'backburner/async_proxy'

module Backburner
  module Performable
    def self.included(base)
      base.send(:include, InstanceMethods)
      base.send(:include, Backburner::Queue)
      base.extend ClassMethods
    end

    module InstanceMethods
      # Return proxy object to enqueue jobs for object
      # Options: `pri` (priority), `delay` (delay in secs), `ttr` (time to respond), `queue` (queue name)
      # @example
      #   @model.async(:pri => 1000).do_something("foo")
      #
      def async(opts={})
        Backburner::AsyncProxy.new(self.class, self.id, opts)
      end
    end # InstanceMethods

    module ClassMethods
      # Return proxy object to enqueue jobs for object
      # Options: `pri` (priority), `delay` (delay in secs), `ttr` (time to respond), `queue` (queue name)
      # @example
      #   Model.async(:ttr => 300).do_something("foo")
      def async(opts={})
        Backburner::AsyncProxy.new(self, nil, opts)
      end

      # Defines perform method for job processing
      # @example
      #   perform(55, :do_something, "foo", "bar")
      def perform(id, method, *args)
        if id # instance
          find(id).send(method, *args)
        else # class method
          send(method, *args)
        end
      end # perform
    end # ClassMethods

  end # Performable
end # Backburner

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
backburner-1.0.0 lib/backburner/performable.rb
backburner-0.4.6 lib/backburner/performable.rb
backburner-0.4.5 lib/backburner/performable.rb
backburner-0.4.4 lib/backburner/performable.rb
backburner-0.4.3 lib/backburner/performable.rb
backburner-0.4.2 lib/backburner/performable.rb
backburner-0.4.1 lib/backburner/performable.rb
backburner-0.4.0 lib/backburner/performable.rb
backburner-0.3.4 lib/backburner/performable.rb
backburner-0.3.3 lib/backburner/performable.rb
backburner-0.3.2 lib/backburner/performable.rb
backburner-0.3.1 lib/backburner/performable.rb
backburner-0.3.0 lib/backburner/performable.rb
backburner-0.2.6 lib/backburner/performable.rb
backburner-0.2.5 lib/backburner/performable.rb
backburner-0.2.0 lib/backburner/performable.rb
backburner-0.1.2 lib/backburner/performable.rb
backburner-0.1.1 lib/backburner/performable.rb
backburner-0.1.0 lib/backburner/performable.rb
backburner-0.0.3 lib/backburner/performable.rb