Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tostart-pickagreatname opened this issue Aug 29, 2024 · 3 comments

Comments

@tostart-pickagreatname
Copy link

tostart-pickagreatname commented Aug 29, 2024

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 rails/rails@e922c59

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 tostart-pickagreatname changed the title Rails 7.2.1 requires enqueue_after_transaction_commit? method on queue adapters Rails 7.2.1 breaks enqueuing without enqueue_after_transaction_commit? method on queue adapters Aug 29, 2024
@tostart-pickagreatname tostart-pickagreatname changed the title Rails 7.2.1 breaks enqueuing without enqueue_after_transaction_commit? method on queue adapters Rails 7.2.X breaks enqueuing without enqueue_after_transaction_commit? method on queue adapters Sep 3, 2024
@tostart-pickagreatname
Copy link
Author

Update, the change actually came in 7.2 not 7.2.1.

@scomma
Copy link

scomma commented Sep 14, 2024

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

@saturnflyer
Copy link

This recommendation by @scomma does not seem to fix it for us.
We added to our application.rb the following

  config.active_job.enqueue_after_transaction_commit = :always

This allowed us to run on rails 7.2 and the latest Que (2.4.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants