Created
September 7, 2016 08:51
-
-
Save coilysiren/d3203d38da32ce7633d69d08180d030e to your computer and use it in GitHub Desktop.
sidekiq worker with arbitrary callback functions
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
# references: | |
# https://github.com/mperham/sidekiq (sidekiq) | |
# https://ruby-doc.org/core-2.3.1/Object.html#method-i-send (ruby's `send` method) | |
# https://robots.thoughtbot.com/ruby-2-keyword-arguments (ruby keywork arguments in general) | |
# https://github.com/mperham/sidekiq/issues/2372 (keyword arguments in sidekiq) | |
# https://github.com/mperham/sidekiq/wiki/Best-Practices (sidekiq best practices) | |
class Worker | |
include Sidekiq::Worker | |
def perform(callback=nil) | |
send *callback unless callback.nil? | |
end | |
end | |
Worker.perform_async(['puts', 'cat']) # outputs "cat" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
will add an in use example soon!