Skip to content

Instantly share code, notes, and snippets.

@coilysiren
Created September 7, 2016 08:51
Show Gist options
  • Save coilysiren/d3203d38da32ce7633d69d08180d030e to your computer and use it in GitHub Desktop.
Save coilysiren/d3203d38da32ce7633d69d08180d030e to your computer and use it in GitHub Desktop.
sidekiq worker with arbitrary callback functions
# 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"
@coilysiren
Copy link
Author

will add an in use example soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment