que-rb / que

A Ruby job queue that uses PostgreSQL's advisory locks for speed and reliability.
MIT License
2.31k stars 188 forks source link

Rails 7.2.X breaks enqueuing without `enqueue_after_transaction_commit?` method on queue adapters #430

Open tostart-pickagreatname opened 2 months ago

tostart-pickagreatname commented 2 months ago

Rails 7.2.1 requires that queues implement the enqueue_after_transaction_commit? method.

The impact of not having this method and upgrading to 7.2.1 is that all job enqueuing fails.

This method is described in https://github.com/rails/rails/commit/e922c59207c406d51541622690737783e0ec338e

This commit also introduced ActiveJob::QueueAdapters::AbstractAdapter which all rails queues now inherit from.

In the future, the best path would be to have the adapter inherit from AbstractAdapter, to avoid new methods breaking job enqueuing.

At this time, however, its default behaviour could simply be implemented.

tostart-pickagreatname commented 1 month ago

Update, the change actually came in 7.2 not 7.2.1.

scomma commented 1 month ago

A workaround for whoever ran into this issue with Rails 7.2 and Que 2.4—put this in your app/jobs/application_job.rb.

class ApplicationJob < ActiveJob::Base
  # Automatically retry jobs that encountered a deadlock
  # retry_on ActiveRecord::Deadlocked

  # Most jobs are safe to ignore if the underlying records are no longer available
  # discard_on ActiveJob::DeserializationError

  # Wait for the transaction to commit before enqueuing
  self.enqueue_after_transaction_commit = :always
end