Skip to content
Mike Perham edited this page Jun 10, 2021 · 6 revisions

faktory_worker_ruby supports ActiveJob, here's how to use it. This page assumes you already have a Faktory server installed and running locally.

1. Install the gem

# Gemfile
gem 'faktory_worker_ruby'
# config/application.rb
config.active_job.queue_adapter = :faktory

2. Define your ActiveJobs:

# app/jobs/some_job.rb
class SomeJob < ApplicationJob
  faktory_options retry: 5, custom: { unique_for: 10.minutes.to_i }
  queue_as :default

  def perform(name)
    puts "Hello, #{name}"
  end
end

Note the use of faktory_options to add custom job options to control various Faktory features.

3. Create a few jobs

$ bundle exec rails c
> SomeJob.perform_later("World")

4. Start a Worker

$ bundle exec faktory-worker

The worker process should perform that job and print out "Hello, World". You've now got Faktory on Rails!

Notes

Processing jobs outside ActiveJob

If you are going to enqueue jobs in Ruby but process them in another language, I recommend sticking with the plain Faktory::Job API. ActiveJob is designed for use by Rails only.