Background jobs: ActiveJob
This course looks at ActiveJob::Base, the framework layer this app's jobs are written against, above whichever backend runs them. It covers how the queue adapter changes per environment, how arguments are serialised as GlobalIDs or plain ids, and when retry_on and discard_on have an exception to catch. It also covers how limits_concurrency and queue_as map onto Solid Queue's tables, the perform callbacks, and how deliver_later enqueues an ActionMailer job through the same adapter.
What you'll learn
- ✓How queue_adapter runs the same job on :async in development and :solid_queue in test and production
- ✓How ActiveJob serialises a record as a GlobalID, and why the app passes a plain id with find_by
- ✓When retry_on and discard_on apply, based on whether an exception reaches perform
- ✓How limits_concurrency writes a concurrency_key and sends a second job to blocked executions
- ✓How queue_as, queue_with_priority and config/queue.yml decide which worker claims a job
- ✓How deliver_later enqueues ActionMailer::MailDeliveryJob, and where perform callbacks fit
The framework layer above the backend
The mid-level course "Solid Queue: job architecture", earlier in this series, looked at the tables where a job's state is stored and claimed. Every one of those tables belongs to Solid Queue, one backend. This app's jobs are never written against Solid Queue directly. They're written against…
Read the full lesson free →Curriculum
7 lessonsThe framework layer above the backend
Shows that the app's jobs use only ActiveJob vocabulary, with the queue adapter chosen per environment.
Arguments across the wire: GlobalID vs. a plain ID
Compares GlobalID arguments, which raise on deleted records, with plain ids and find_by, which return nil.
retry_on and discard_on: where they fit, and where they don't
Explains why DeliverWebhookJob uses retry_on while FetchSiteIconJob's service rescues every network error itself.
limits_concurrency: the DSL over a mechanism you can verify
Shows limits_concurrency writing a concurrency_key and blocking a second job with the same key.
queue_as and where "the queue" lives
Covers queue_as and queue_with_priority as columns, and the worker queue lists in config/queue.yml.
ActiveJob callbacks, and the second real usage path: ActionMailer
Shows deliver_later enqueuing an ActionMailer job through ActiveJob, and the perform callbacks the app leaves unused.
Putting it together: what ActiveJob gives this app's jobs
Reviews each ActiveJob feature in the app and the handler precedence rule from ActiveSupport::Rescuable.