Created
January 7, 2016 17:07
-
-
Save Fryie/3e1be5b2b7dd29413c4d to your computer and use it in GitHub Desktop.
Sidekiq Proxy Workers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailWorkerProxy | |
include WorkerProxy | |
sidekiq_options queue: 'email', retry: false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sidekiq' | |
# set up / connect Sidekiq | |
Sidekiq::Client.push( | |
class: 'EmailWorker', | |
queue: 'email', | |
retry: false, | |
args: ['[email protected]', 'Hello World'] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EmailWorker.perform_async('[email protected]', 'Hello World') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EmailWorkerProxy.perform_async('[email protected]', 'Hello World') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailWorker | |
include Sidekiq::Worker | |
sidekiq_options queue: 'email', retry: false | |
# dequeuing and executing job | |
def perform(recipient, message) | |
send_email recipient, message | |
end | |
private | |
def send_email(recipient, message) | |
# code omitted | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module WorkerProxy | |
def self.included(base) | |
base.send(:include, Sidekiq::Worker) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
# override | |
def client_push(item) | |
# get sidekiq options defined in proxy | |
extended_item = get_sidekiq_options.merge(item) | |
# strip 'Proxy' from class name | |
proxied_class_name = to_s[0..-6] | |
super(extended_item.merge 'class' => proxied_class_name) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment