TakeCare
Sidekiq wrapper for activerecord model (or any class which instances are fetched by #id)
Method #take_care(method, *args) that delegates actual performing of own method to sidekiq
Installation
Add this line to your application's Gemfile:
gem 'take_care'
And then execute:
$ bundle
Or install it yourself as:
$ gem install take_care
Usage
Include TakeCare::Reliable into your model and you will get #take_care method inside of it.
class Human < ActiveRecord::Base
include TakeCare::Reliable
def hard_work(box1, box2)
# Code that needs to be executed in background
end
end
human = Human.create(name: 'Alex')
human.take_care :hard_work, 'heavy box', 'second heavy box' # This goes to sidekiq
human.take_care_of :hard_work, 'heavy box', 'second heavy box' # Same using alias
# Same using dynamic methods (method is defined after first call)
human.take_care_hard_work 'heavy box', 'second heavy box'
# Or
human.take_care_of_hard_work 'heavy box', 'second heavy box'
There is also support for class methods for all kind of classes (not only ActiveRecord::Base).
class Human
include TakeCare::Reliable
def self.do_stuff(s1, s2)
# Code that needs to be executed in background
end
end
Human.take_care :do_stuff, 'arg1', 'arg2' # This goes to sidekiq
Human.take_care_of :do_stuff, 'arg1', 'arg2' # Same using alias
# Same using dynamic methods (method is defined after first call)
Human.take_care_do_stuff 'arg1', 'arg2'
# Or
Human.take_care_of_do_stuff 'arg1', 'arg2'
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request