-
Notifications
You must be signed in to change notification settings - Fork 23
Installation & Usage in pure Ruby
To install the gem, simply run;
gem install navvy
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;
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'
Connect to your database;
MongoMapper.database = 'my_database'
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
Now, add your job to Navvy’s queue (I’m doing this 300 times);
300.times do
Navvy::Job.enqueue(Mailer, :send_lots)
end
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
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.