Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Installation & Usage in pure Ruby

rodrigo3n edited this page Oct 4, 2010 · 1 revision

Installing the gem

To install the gem, simply run;

gem install navvy

Setting up your database

If you’re using ActiveRecord, Sequel or Datamapper you should set up your database for Navvy to use. Simply running any of these will get you up and running on a sqlite database;

Requiring Navvy

Now, create a file (mine is called mailer.rb) and require Navvy;

require 'rubygems'
require 'navvy'

Choose your job adapter (I’m using MongoMapper in this example) and include it;

require 'navvy/job/mongo_mapper'

Connecting to your database

Connect to your database;

MongoMapper.database = 'my_database'

Creating a job

Navvy needs a job to process. I’ve created a Mailer that can deliver lots of messages at once;

class Mailer
  def self.send_lots()
    'sent!'
  end
end

Enqueueing your job

Now, add your job to Navvy’s queue (I’m doing this 300 times);

300.times do
  Navvy::Job.enqueue(Mailer, :send_lots)
end

Starting the worker

Now, add this line to get the worker to start at the end of your file;

Navvy::Worker.start

If you run your little “app”, you’ll see the worker doing its job;

ruby mailer.rb

Done!

Congratulations. You just got Navvy working. In a real application you’d probably want to keep the worker running while some other Ruby script enqueues jobs but you get the point, right? Also, you can hop on over to the Getting started guide for more information on how to use Navvy.