A small, Ruby superset of Komrade's HTTP API
Email [email protected] with your heroku email address for a beta pass.
$ heroku addons:add komrade:test
$ gem install komrade-client
- Install Gem
- Minimalist Example
- Rails Example
- Komrade Dashboard
Gemfile
source :rubygems
gem 'komrade-client', '~> 1.0.15'
This is the absolute bare minimum to see Komrade in action.
$ export KOMRADE_URL=https://{heroku_username}:{heroku_password}@service.komrade.io
$ ruby -r komrade-client -e 'Komrade::Queue.enqueue("puts", "hello world")'
$ ruby -r komrade-client -e 'puts Komrade::Queue.dequeue'
You should see "hello world" output in your terminal.
To get started add gem 'komrade-client', '~> 1.0.15'
to your Gemfile. Then run
rails g komrade
. This will add a komrade-worker process to your Procfile (feel
free to edit your Procfile by hand if you prefer).
Your Procfile now should look something like this:
web: bundle exec rails s
komrade-worker: bundle exec rake komrade:work
This is an example of a Rails model that sends a welcome email upon user sign up.
The only code that is unique to Komrade here is the Komrade::Queue.enqueue
method.
This method takes a method as a string and any parameters you want to pass to that method.
class User < ActiveRecord::Base
after_create :enqueue_welcome_email
def self.send_welcome_email(id)
if u = find(id)
Mailer.welcome(u).deliver
end
end
def enqueue_welcome_email
Komrade::Queue.enqueue("User.send_welcome_email", self.id)
end
end
When you deploy your code, the will queue be ready to accept jobs, and the worker process is waiting to do the work.
$ heroku addons:open komrade:test