This simple Rails app shows off the features of QueueClassic. Specifically, an application that users multiple queues with distinct workers. Some files to note:
- config/initializers/queue_classic.rb
- db/migrate/20110519195855_add_queue_classic_tables.rb
- app/models/user.rb
- app/helpers/users_helper.rb
- app/clock.rb
- Procfile
- Rakefile
bundle
rake db:create
rake db:migrate
update DATABASE_URL in config/initializers/queue_classic.rb
rake qc:load_functions
There are 3 queues in this app: Default, email_jobs, image_jobs.
We are only really using email_jobs and image_jobs, so we will attach workers on these queues.
bundle exec rake qc:work QUEUE="image_jobs"
bundle exec rake qc:work QUEUE="email_jobs"
All of this is encoded in our Procfile. You are using Procfile, right?
Now, to start these workers and our web process, execute foreman start
in the root directory of the app.
foreman start (If you have not already done so.)
Visit /users/new
Click "create"
Watch output on the worker terminal windows
In app/clock.rb we setup a schedule for sending out welcome emails every day. Queue Classic encourages you to handle your scheduling of work via a gem that specializes in scheduling; clockwork. In our clock file, we schedule a method call for each day. This method call will find all of the users who have not received a welcome email and send each of those users a welcome email.