Sha256: bdcfacf039cc72139722ab9142d7fe6fb9a6d55a34b4ae1c4f901b4514adc0fd

Contents?: true

Size: 816 Bytes

Versions: 2

Compression:

Stored size: 816 Bytes

Contents

require 'sidekiq/client'

module Sidekiq

  ##
  # Include this module in your worker class and you can easily create
  # asynchronous jobs:
  #
  # class HardWorker
  #   include Sidekiq::Worker
  #
  #   def perform(*args)
  #     # do some work
  #   end
  # end
  #
  # Then in your Rails app, you can do this:
  #
  #   HardWorker.perform_async(1, 2, 3)
  #
  # Note that perform_async is a class method, perform is an instance method.
  module Worker
    def self.included(base)
      base.extend(ClassMethods)
    end

    def info(msg)
      print "#{msg}\n"
    end
    alias_method :log, :info

    def debug(msg)
      print "#{msg}\n" if $DEBUG
    end

    module ClassMethods
      def perform_async(*args)
        Sidekiq::Client.push('class' => self.name, 'args' => args)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-0.5.1 lib/sidekiq/worker.rb
sidekiq-0.5.0 lib/sidekiq/worker.rb