The Delayed Job adapter will be removed from Rails soon. This gem extracts it so that you can continue using Delayed Job with Active Job.
If you are using a version of Rails that includes a Delayed Job adapter, using this gem will replace Rails' version with this gem's.
This gem implements some new features beyond what the Rails adapter did. See features for instructions.
- Support for
perform_all_later
. - You can set
run_at
when bulk enqueueing. - You can persist extra attributes on a job by writing to
job_attributes
.
gem install delayed_job-active_job
Configure the Active Job backend. See the Rails docs for more information.
# config/application.rb
config.active_job.queue_adapter = :delayed_job
This gem supports all the base functionality of any Active Job adapter. So anything in https://guides.rubyonrails.org/active_job_basics.html should work. If it doesn't please log an issue.
ActiveJob.perform_all_later([HelloJob.new("Jamie"), HelloJob.new("John"), HelloJob.new("Alex")])
Under the hood, this uses Delayed::Job.insert_all
to insert all the jobs into the database using a single SQL query.
job = HelloJob.new("Alex")
job.run_at = 1.hour.from_now
ActiveJob.perform_all_later([job])
This is the equivalent to HelloJob.set(wait: 1.hour).perform_later("Alex")
.
job = HelloJob.new("Alex")
job.job_attributes = { metadata: "foo" }
job.enqueue
job = HelloJob.new("Alex")
job.job_attributes = { metadata: "foo" }
ActiveJob.perform_all_later([job])
These examples would write "foo"
into the metadata
column on the delayed_jobs
table. This works with any type of column, not just strings.
If you want to report a bug, or have ideas, feedback or questions about the gem, let me know via GitHub issues and I will do my best to provide a helpful answer. Happy hacking!
The gem is available as open source under the terms of the MIT License.
Pull requests are welcome!