Skip to content

Commit f893ff2

Browse files
authored
Merge pull request rails#54101 from rosa/fix-solid-queue-dev-instructions
Fix some parts of the Solid Queue documentation
2 parents f9ce8f3 + b6804ec commit f893ff2

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

guides/source/active_job_basics.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ development:
173173
NOTE: The key `queue` from the database configuration needs to match the key
174174
used in the configuration for `config.solid_queue.connects_to`.
175175

176-
You can run the migrations for the `queue` database to ensure all the tables in
177-
queue database are created:
176+
You can then run `db:prepare` to ensure the `queue` database in `development` has all the required tables:
178177

179178
```bash
180-
$ bin/rails db:migrate:queue
179+
$ bin/rails db:prepare
181180
```
182181

183182
TIP: You can find the default generated schema for the `queue` database in
@@ -219,6 +218,13 @@ production:
219218
migrations_paths: db/queue_migrate
220219
```
221220

221+
Make sure you run `db:prepare` so your database is ready to use:
222+
223+
```bash
224+
$ bin/rails db:prepare
225+
```
226+
227+
222228
### Configuration
223229

224230
The configuration options for Solid Queue are defined in `config/queue.yml`.
@@ -301,9 +307,11 @@ its own or at the end of a queue name to match all queues with the same prefix.
301307
You can't specify queue names such as `*_some_queue`.
302308

303309
WARNING: Using wildcard queue names (e.g., `queues: active_storage*`) can slow
304-
down polling performance due to the need for a `DISTINCT` query to identify all
305-
matching queues, which can be slow on large tables. For better performance, it’s
306-
best to specify exact queue names instead of using wildcards.
310+
down polling performance in SQLite and PostgreSQL due to the need for a `DISTINCT`
311+
query to identify all matching queues, which can be slow on large tables in these RDBMS.
312+
For better performance, it’s best to specify exact queue names instead of using
313+
wildcards. Read more about this in [Queues specification and performance in the
314+
Solid Queue documentation](https://github.com/rails/solid_queue?tab=readme-ov-file#queues-specification-and-performance)
307315

308316
Active Job supports positive integer priorities when enqueuing jobs (see
309317
[Priority section](#priority)). Within a single queue, jobs are picked based on
@@ -414,14 +422,22 @@ end
414422

415423
### Transactional Integrity on Jobs
416424

417-
By default, Solid Queue uses a separate database from your main application.
418-
This avoids issues with transactional integrity, which ensures that jobs are
419-
only enqueued if the transaction commits.
425+
⚠️ Having your jobs in the same ACID-compliant database as your application data
426+
enables a powerful yet sharp tool: taking advantage of transactional integrity
427+
to ensure some action in your app is not committed unless your job is also committed
428+
and vice versa, and ensuring that your job won't be enqueued until the transaction
429+
within which you're enqueuing it is committed. This can be very powerful and useful,
430+
but it can also backfire if you base some of your logic on this behaviour,
431+
and in the future, you move to another active job backend, or if you simply move
432+
Solid Queue to its own database, and suddenly the behaviour changes under you.
433+
434+
Because this can be quite tricky and many people shouldn't need to worry about it,
435+
by default Solid Queue is configured in a different database as the main app.
420436

421-
However, if you use Solid Queue in the same database as your app, you can enable
422-
transactional integrity with Active Job’s `enqueue_after_transaction_commit`
423-
option which can be enabled for individual jobs or all jobs through
424-
`ApplicationJob`:
437+
However, if you use Solid Queue in the same database as your app, you can make sure you
438+
don't rely accidentallly on transactional integrity with Active Job’s
439+
`enqueue_after_transaction_commit` option which can be enabled for individual jobs or
440+
all jobs through `ApplicationJob`:
425441

426442
```ruby
427443
class ApplicationJob < ActiveJob::Base
@@ -430,7 +446,7 @@ end
430446
```
431447

432448
You can also configure Solid Queue to use the same database as your app while
433-
avoiding transactional integrity issues by setting up a separate database
449+
avoiding relying on transactional integrity by setting up a separate database
434450
connection for Solid Queue jobs. Read more about [Transactional Integrity in the
435451
Solid Queue
436452
documentation](https://github.com/rails/solid_queue?tab=readme-ov-file#jobs-and-transactional-integrity)
@@ -457,7 +473,7 @@ Each task specifies a `class` or `command` and a `schedule` (parsed using
457473
jobs, such as in the example for `MyJob` where `args` are passed. This can be
458474
passed as a single argument, a hash, or an array of arguments that can also
459475
include kwargs as the last element in the array. This allows jobs to run
460-
periodically or at specified times.
476+
periodically at specified times.
461477

462478
Read more about [Recurring Tasks in the Solid Queue
463479
documentation](https://github.com/rails/solid_queue?tab=readme-ov-file#recurring-tasks).

0 commit comments

Comments
 (0)