Skip to content

Commit 805ef0c

Browse files
committed
Remove deprecated adapter specific deferred enqueueing of jobs
1 parent 42ce2ac commit 805ef0c

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

README.md

+6-17
Original file line numberDiff line numberDiff line change
@@ -350,24 +350,13 @@ to your `puma.rb` configuration.
350350
## Jobs and transactional integrity
351351
:warning: Having your jobs in the same ACID-compliant database as your application data enables a powerful yet sharp tool: taking advantage of transactional integrity to ensure some action in your app is not committed unless your job is also committed and viceversa, and ensuring that your job won't be enqueued until the transaction within which you're enqueuing it is committed. This can be very powerful and useful, but it can also backfire if you base some of your logic on this behaviour, and in the future, you move to another active job backend, or if you simply move Solid Queue to its own database, and suddenly the behaviour changes under you.
352352

353-
Because this can be quite tricky and many people shouldn't need to worry about it, by default Solid Queue is configured in a different database as the main app, **job enqueuing is deferred until any ongoing transaction is committed** thanks to Active Job's built-in capability to do this. This means that even if you run Solid Queue in the same DB as your app, you won't be taking advantage of this transactional integrity.
353+
An option which doesn't rely on this transactional integrity and which Active Job provides is to defer the enqueueing of a job inside an Active Record transaction until that transaction successfully commits. This option can be set via the [`enqueue_after_transaction_commit`](https://edgeapi.rubyonrails.org/classes/ActiveJob/Enqueuing.html#method-c-enqueue_after_transaction_commit) class method on the job level and is by default disabled. Either it can be enabled for individual jobs or for all jobs through `ApplicationJob`:
354354

355-
If you prefer to change this, you can set [`config.active_job.enqueue_after_transaction_commit`](https://edgeguides.rubyonrails.org/configuring.html#config-active-job-enqueue-after-transaction-commit) to `never`. You can also set this on a per-job basis.
356-
357-
If you set that to `never` but still want to make sure you're not inadvertently on transactional integrity, you can make sure that:
358-
- Your jobs relying on specific data are always enqueued on [`after_commit` callbacks](https://guides.rubyonrails.org/active_record_callbacks.html#after-commit-and-after-rollback) or otherwise from a place where you're certain that whatever data the job will use has been committed to the database before the job is enqueued.
359-
- Or, you configure a different database for Solid Queue, even if it's the same as your app, ensuring that a different connection on the thread handling requests or running jobs for your app will be used to enqueue jobs. For example:
360-
361-
```ruby
362-
class ApplicationRecord < ActiveRecord::Base
363-
self.abstract_class = true
364-
365-
connects_to database: { writing: :primary, reading: :replica }
366-
```
367-
368-
```ruby
369-
config.solid_queue.connects_to = { database: { writing: :primary, reading: :replica } }
370-
```
355+
```ruby
356+
class ApplicationJob < ActiveJob::Base
357+
self.enqueue_after_transaction_commit = true
358+
end
359+
```
371360

372361
## Recurring tasks
373362

lib/active_job/queue_adapters/solid_queue_adapter.rb

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ module QueueAdapters
88
#
99
# Rails.application.config.active_job.queue_adapter = :solid_queue
1010
class SolidQueueAdapter
11-
def enqueue_after_transaction_commit?
12-
true
13-
end
14-
1511
def enqueue(active_job) # :nodoc:
1612
SolidQueue::Job.enqueue(active_job)
1713
end

0 commit comments

Comments
 (0)