-
Notifications
You must be signed in to change notification settings - Fork 31
ActiveJob
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.
# Gemfile
gem 'faktory_worker_ruby'
# config/application.rb
config.active_job.queue_adapter = :faktory
# 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.
$ bundle exec rails c
> SomeJob.perform_later("World")
$ bundle exec faktory-worker
The worker process should perform that job and print out "Hello, World". You've now got Faktory on Rails!
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.