Getting started

jeffkreeftmeijer edited this page Sep 13, 2010 · 2 revisions

Great, you installed Navvy. If you haven’t, check out the Installation guide.

Enqueueing jobs

To enqueue a job from your application, do this;

Navvy::Job.enqueue(Object, :method, argument1, argument2, ...)

Let’s say we have a class called Cow with a method called #speak.

class Cow
  def self.speak

If we want to enqueue the Cow#speak method, we’d just do this;

Navvy::Job.enqueue(Cow, :speak)

You can also pass arguments. Let’s say the Cow has another method called #name, like this;

class Cow
    "#{self.speak}, my name is #{name}."

If we want to enqueue the Cow telling its name, we’d do that like this;

Navvy::Job.enqueue(Cow, :name, 'Betsy')

The jobs get enqueued in our database table and will stay there until the worker comes by.

The worker

Navvy has a worker to process the jobs you put in the database. If you’re using Rails and have included the Rake tasks (like explained in “Installation on Rails 2.x”). You can start the worker by simply running;

rake navvy:work

Otherwise, you’ll have to start the worker in Ruby;


The worker will check the database for new jobs every 5 seconds. If it finds anything, it’ll run it and give feedback in the terminal window.

Let’s stay with the Cow example. If we enqueued the Cow#speak method, the worker will fetch it, run it and output this in green;

* Cow.speak() => Moo!

That way we know that the job didn’t fail. If the job failed the output will be colored red and the exception message will be shown so you can go fix it. ;)

If you want to stop the worker just press CTRL + C.