Skip to content

TandaHQ/delayed_job-active_job

Repository files navigation

delayed_job-active_job

Gem Version Gem Downloads GitHub Workflow Status

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.

Quick start

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

Features

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.

perform_all_later

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.

Set run_at when bulk enqueueing

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").

Extra attributes via job_attributes

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.

Support

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!

License

The gem is available as open source under the terms of the MIT License.

Contribution guide

Pull requests are welcome!