A Mongoid backend for delayed_job.
See the CHANGELOG for what's new in each release.
delayed_job_mongoid requires Ruby 3.2 or later and Mongoid 7 or later. It is tested against Mongoid 7, 8 and 9.
For Mongoid 5 and 6, use version 3.0 of this gem. For Mongoid 3 and 4, use version 2.x.
Add the gem to your Gemfile:
gem 'delayed_job_mongoid'Then create the indexes (don't forget to do this in production):
bin/rails runner 'Delayed::Backend::Mongoid::Job.create_indexes'
To generate bin/delayed_job:
bin/rails generate delayed_job
That's it. Use delayed_job as normal.
By default, the Mongo Ruby Driver will print log lines every
5 seconds as Delayed Job polls your database. Use the following
plugin to silence logs which happen while polling (except error
level) and only log operations which happen during job execution.
# in config/initializers/delayed_job.rb
require 'delayed/plugins/mongo_silencer'
Delayed::Worker.plugins << Delayed::Plugins::MongoSilencerTo ensure thread safety, this plugin requires your Mongo::Logger.logger
to be an instance of ActiveSupport::Logger class. It will ignore instances
of the Ruby standard library Logger class.
Delayed Job allows specifying a custom backend class for jobs. For example, you may wish to specify a different database collection name. To do this:
# in an initializer
class MyJob
include Mongoid::Document
store_in(collection: :my_jobs)
include Delayed::Backend::Mongoid::Mixin
end
Delayed::Worker.backend = MyJob
# in your application
MyJob.enqueue(job_object)