mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
fd46c5471a
Configure client middleware chain by default Middleware entries should be unique Change client#push to return boolean based on pushed or not.
46 lines
903 B
Ruby
46 lines
903 B
Ruby
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
|
|
|
|
def queue(name)
|
|
Sidekiq::Client.queues[self.name] = name.to_s
|
|
end
|
|
end
|
|
end
|
|
end
|