Sklaventreiber

Sklaventreiber is a Ruby gem that manages your worker when you're using Navvy and Sequel with Heroku. It hires one if there are jobs to be done and fires him if not.

Slaventreiber can either be used as a Sequel plugin or as a worker process.

Sklaventreiber, der (eng.: slave driver): German expression for a overly demanding boss that ignores his employees' health and happiness.

Installation

Sklaventreiber is NOT usable as of now, because it still requires a custom version of Navvy. This is going to change.

Plugin

Add this line to your application's Gemfile:

gem 'sklaventreiber'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sklaventreiber

Worker

Add these lines to your Rakefile:

require "sklaventreiber"
require "sklaventreiber/tasks"

Usage

Sklaventreiber expects a few environment variables to be set.

# either this
HEROKU_API_KEY=< your heroku api key >
# or this
HEROKU_USERNAME=< your heroku username >
HEROKU_PASSWORD=< your heroku password >
# but always this
HEROKU_APP=< your heroku app name >

You can use either the API key or the username/password combination. Sklaventreiber will try to connect via the API key and fall back to username/password if it's not possible.

Sklaventreiber logs to standard output via puts. If you don't like that you can turn it off.

SKLAVENTREIBER_LOG="false"

Plugin

There is nothing to be done other than adding Sklaventreiber to your Gemfile. It hooks automatically into Navvy::Job. Just make sure you require it after Navvy and Sequel.

require "sequel"
require "navvy"
require "navvy/job/sequelhook"
require "sklaventreiber"

Worker

Execute the following to start Sklaventreiber as a worker:

rake sklaventreiber:work

Sklaventreiber checks every 10 seconds if it needs to scale your Heroku worker. For a custom interval set

SKLAVENTREIBER_SLEEPTIME=< your custom interval in seconds >

Contributing

For development you should also set these environment variables:

SKLAVENTREIBER_MOCK=< if heroku-api should run in mock mode >
DATABASE_URL=< database://user:password@host:port/database_name >

Then:

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Testing the worker

I tried to start all three necessary processes (Navvy, Sklaventreiber, test code) using foreman. Because my test code contained a few sleep statements to wait for Navvy and Sklaventreiber, foreman halted all three processes instead of only the test code. I honestly have no idea why. Testing the worker was then done using three different terminals for the processes and looking if they behave as expected.