2012-01-25 16:32:51 -05:00
|
|
|
require 'sidekiq/client'
|
2012-01-23 17:05:03 -05:00
|
|
|
|
2012-01-16 23:05:38 -05:00
|
|
|
module Sidekiq
|
|
|
|
|
2012-01-25 16:32:51 -05:00
|
|
|
##
|
|
|
|
# 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
|
2012-01-25 16:53:00 -05:00
|
|
|
def self.included(base)
|
|
|
|
base.extend(ClassMethods)
|
|
|
|
end
|
|
|
|
|
2012-02-14 12:00:26 -05:00
|
|
|
def logger
|
|
|
|
Sidekiq::Util.logger
|
2012-01-25 16:53:00 -05:00
|
|
|
end
|
2012-01-21 19:42:21 -05:00
|
|
|
|
2012-01-25 16:53:00 -05:00
|
|
|
module ClassMethods
|
|
|
|
def perform_async(*args)
|
|
|
|
Sidekiq::Client.push('class' => self.name, 'args' => args)
|
|
|
|
end
|
2012-02-10 23:20:01 -05:00
|
|
|
|
|
|
|
def queue(name)
|
2012-02-15 14:28:19 -05:00
|
|
|
Sidekiq::Client.queue_mappings[self.name] = name.to_s
|
2012-02-10 23:20:01 -05:00
|
|
|
end
|
2012-01-16 23:05:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|