async-job-adapter-active_job 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/getting-started.md +34 -66
- data/context/index.yaml +16 -2
- data/context/production-deployment.md +79 -0
- data/context/queue-configuration.md +120 -0
- data/context/testing.md +91 -0
- data/lib/async/job/adapter/active_job/dispatcher.rb +3 -1
- data/lib/async/job/adapter/active_job/service.rb +1 -1
- data/lib/async/job/adapter/active_job/version.rb +1 -1
- data/readme.md +14 -8
- data.tar.gz.sig +0 -0
- metadata +7 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 438122b9f40ef9fd97ebe48bb50ff7a015a4dcd4837f6d9cd70cfb2dfba86a70
|
|
4
|
+
data.tar.gz: 19308266ced3a1fe91990d4b865aeb68cbdd5b82c1f99e4f62de068c0e0f97f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 64ec94d3dd9421049c342ab7702cb2f9ed4ae38859f76ba5a41d9f09bb1cc0a459f43d5229969a10a58e800e98ae0d68e065a8e65ab06d63e75694bccf13cfd7
|
|
7
|
+
data.tar.gz: 26733df41fe820a33a31dddae659610ee11a7d709f2b3fcbff4d0319e850c6b46ac676cfa4d8566cc0ffbf5aa10a6c0fdacc418836d70f1e6fdf036206329d55
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/context/getting-started.md
CHANGED
|
@@ -1,98 +1,66 @@
|
|
|
1
1
|
# Getting Started
|
|
2
2
|
|
|
3
|
-
This guide explains how to
|
|
3
|
+
This guide explains how to use `async-job-adapter-active_job` to run Rails Active Job workloads with inline or Redis-backed queues.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Add the
|
|
7
|
+
Add the adapter to your Rails application:
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```shell
|
|
10
10
|
$ bundle add async-job-adapter-active_job
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Core Concepts
|
|
14
14
|
|
|
15
|
-
The
|
|
15
|
+
The adapter connects Active Job's standard API to an `async-job` processing pipeline:
|
|
16
16
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
17
|
+
- ruby:`ActiveJob::QueueAdapters::AsyncJobAdapter` receives jobs from `perform_later` and dispatches their serialized payloads.
|
|
18
|
+
- A queue definition maps an Active Job queue name to an `async-job` processor.
|
|
19
|
+
- The processor determines where jobs wait and run. The built-in inline processor keeps work in the application process, while processors such as Redis support separate workers.
|
|
20
|
+
- ruby:`Async::Job::Adapter::ActiveJob::Executor` deserializes queued payloads and invokes Active Job.
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
Active Job remains responsible for arguments, callbacks, retries, and error handling. This gem supplies the queue adapter and worker integration.
|
|
21
23
|
|
|
22
|
-
##
|
|
24
|
+
## Quick Start
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
The built-in inline queue is the quickest way to get started because it does not require Redis or a separate worker. It is useful during development and for non-critical work that can remain in the application process.
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
Configure Active Job to use the adapter in `config/application.rb`:
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
config.active_job.queue_adapter = :async_job
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### `Async::Job` Queue Configuration
|
|
37
|
-
|
|
38
|
-
You can define your queues in an initializer file (e.g., `config/initializers/async_job.rb`). Here is an example configuration that sets up two queues: a default queue using Redis and a local queue that processes jobs inline. NOTE that inline jobs will run **sequentially** (that is, not concurrently) outside of an `Async` event loop (that is to say, your jobs will block unless you're running your server using falcon).
|
|
39
|
-
|
|
40
|
-
``` ruby
|
|
41
|
-
# config/initializers/async_job.rb
|
|
42
|
-
|
|
43
|
-
require "async/job/processor/redis"
|
|
44
|
-
require "async/job/processor/inline"
|
|
45
|
-
|
|
46
|
-
Rails.application.configure do
|
|
47
|
-
# Create a queue for the "default" backend:
|
|
48
|
-
config.async_job.define_queue "default" do
|
|
49
|
-
dequeue Async::Job::Processor::Redis
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# Create a queue named "local" which uses the Inline backend:
|
|
53
|
-
config.async_job.define_queue "local" do
|
|
54
|
-
dequeue Async::Job::Processor::Inline
|
|
30
|
+
```ruby
|
|
31
|
+
module MyApplication
|
|
32
|
+
class Application < Rails::Application
|
|
33
|
+
config.active_job.queue_adapter = :async_job
|
|
55
34
|
end
|
|
56
35
|
end
|
|
57
36
|
```
|
|
58
37
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Rather than using `Async::Job` for all jobs, you could opt in using a specific queue adapter for a specific job. Here is an example:
|
|
38
|
+
Create an Active Job as usual. Define retry and discard behavior on the job so expected failures are handled explicitly:
|
|
62
39
|
|
|
63
|
-
```
|
|
64
|
-
class
|
|
65
|
-
|
|
66
|
-
|
|
40
|
+
```ruby
|
|
41
|
+
class SearchIndexRefreshJob < ApplicationJob
|
|
42
|
+
queue_as :default
|
|
43
|
+
retry_on SearchIndex::Unavailable, wait: 5.seconds, attempts: 3
|
|
44
|
+
discard_on ActiveRecord::RecordNotFound
|
|
67
45
|
|
|
68
|
-
|
|
46
|
+
def perform(product_id)
|
|
47
|
+
Product.find(product_id).refresh_search_index!
|
|
48
|
+
end
|
|
69
49
|
end
|
|
70
50
|
```
|
|
71
51
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
If you are using a queue that requires a server (e.g. Redis), you will need to run a server. A simple server is provided `async-job-adapter-active_job-server`, which by default will run all define queues.
|
|
52
|
+
Enqueue it with `perform_later`:
|
|
75
53
|
|
|
76
|
-
```
|
|
77
|
-
|
|
54
|
+
```ruby
|
|
55
|
+
SearchIndexRefreshJob.perform_later(product.id)
|
|
78
56
|
```
|
|
79
57
|
|
|
80
|
-
|
|
58
|
+
Scheduled jobs use the standard Active Job API too:
|
|
81
59
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
60
|
+
```ruby
|
|
61
|
+
SearchIndexRefreshJob.set(wait: 5.minutes).perform_later(product.id)
|
|
62
|
+
```
|
|
85
63
|
|
|
86
|
-
|
|
64
|
+
That is enough for a working setup. The adapter provides a `default` queue backed by ruby:`Async::Job::Processor::Inline`.
|
|
87
65
|
|
|
88
|
-
|
|
89
|
-
class MyJob < ApplicationJob
|
|
90
|
-
queue_as :default
|
|
91
|
-
|
|
92
|
-
def perform(message)
|
|
93
|
-
puts message
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
MyJob.perform_later("Hello, world!")
|
|
98
|
-
```
|
|
66
|
+
The inline processor is intentionally simple: jobs remain in the application process and will not survive a restart. Inside an Async event loop, such as a Rails application served by Falcon, jobs can run concurrently in background tasks. Outside an Async event loop, `perform_later` waits for the job to finish before returning.
|
data/context/index.yaml
CHANGED
|
@@ -3,10 +3,24 @@
|
|
|
3
3
|
---
|
|
4
4
|
description: A asynchronous job queue for Ruby on Rails.
|
|
5
5
|
metadata:
|
|
6
|
+
bug_tracker_uri: https://github.com/socketry/async-job-adapter-active_job/issues
|
|
7
|
+
changelog_uri: https://github.com/socketry/async-job-adapter-active_job/blob/main/releases.md
|
|
6
8
|
documentation_uri: https://socketry.github.io/async-job-adapter-active_job/
|
|
7
9
|
source_code_uri: https://github.com/socketry/async-job-adapter-active_job.git
|
|
8
10
|
files:
|
|
9
11
|
- path: getting-started.md
|
|
10
12
|
title: Getting Started
|
|
11
|
-
description: This guide explains how to
|
|
12
|
-
|
|
13
|
+
description: This guide explains how to use `async-job-adapter-active_job` to run
|
|
14
|
+
Rails Active Job workloads with inline or Redis-backed queues.
|
|
15
|
+
- path: testing.md
|
|
16
|
+
title: Testing
|
|
17
|
+
description: This guide explains how to test Active Job workloads without running
|
|
18
|
+
`async-job` queues inline during every test.
|
|
19
|
+
- path: production-deployment.md
|
|
20
|
+
title: Production Deployment
|
|
21
|
+
description: This guide explains how to deploy `async-job-adapter-active_job` with
|
|
22
|
+
Redis-backed queues and separate worker processes.
|
|
23
|
+
- path: queue-configuration.md
|
|
24
|
+
title: Queue Configuration
|
|
25
|
+
description: This guide explains how to configure `async-job` queue definitions,
|
|
26
|
+
route Active Jobs, and adopt the adapter incrementally.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Production Deployment
|
|
2
|
+
|
|
3
|
+
This guide explains how to deploy `async-job-adapter-active_job` with Redis-backed queues and separate worker processes.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The built-in inline processor keeps jobs inside the Rails process. That is convenient for development, but jobs cannot survive a process restart or be consumed by another machine.
|
|
8
|
+
|
|
9
|
+
Use a shared queue and separate workers when jobs must:
|
|
10
|
+
|
|
11
|
+
- Survive web process restarts.
|
|
12
|
+
- Run outside request-serving processes.
|
|
13
|
+
- Be distributed across one or more worker machines.
|
|
14
|
+
|
|
15
|
+
Keep the inline processor when those operational guarantees are unnecessary; it has fewer moving parts and requires no external service.
|
|
16
|
+
|
|
17
|
+
## Installing the Redis Processor
|
|
18
|
+
|
|
19
|
+
Redis support is provided by a separate gem:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
$ bundle add async-job-processor-redis
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Ensure a Redis service is available to both the Rails and worker processes.
|
|
26
|
+
|
|
27
|
+
## Configuring the Queue
|
|
28
|
+
|
|
29
|
+
Replace the built-in `default` queue definition in `config/initializers/async_job.rb`:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require "async/job/processor/redis"
|
|
33
|
+
|
|
34
|
+
Rails.application.configure do
|
|
35
|
+
config.async_job.define_queue "default" do
|
|
36
|
+
dequeue Async::Job::Processor::Redis
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The processor connects to Redis on its local default endpoint unless another endpoint is provided. With one logical queue, the default `async-job` prefix is sufficient. Configure distinct, stable prefixes when multiple queue definitions share a Redis endpoint.
|
|
42
|
+
|
|
43
|
+
## Starting Workers
|
|
44
|
+
|
|
45
|
+
Run the bundled worker from the Rails application root so it can load `config/environment.rb`:
|
|
46
|
+
|
|
47
|
+
```shell
|
|
48
|
+
$ RAILS_ENV=production bundle exec async-job-adapter-active_job-server
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The server loads the Rails environment and starts every defined queue. The service container supervises worker instances and reports their readiness.
|
|
52
|
+
|
|
53
|
+
If the command cannot run from the application root, set `RAILS_ROOT` explicitly:
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
$ RAILS_ROOT=/srv/my-application RAILS_ENV=production bundle exec async-job-adapter-active_job-server
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Selecting Queues
|
|
60
|
+
|
|
61
|
+
Worker groups can listen to a subset of definitions. Provide their names as a comma-separated list:
|
|
62
|
+
|
|
63
|
+
```shell
|
|
64
|
+
$ ASYNC_JOB_ADAPTER_ACTIVE_JOB_QUEUE_NAMES=default,critical bundle exec async-job-adapter-active_job-server
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The values must be definition names, not aliases, and should not contain spaces. Run at least one worker group for every Redis-backed definition that should make progress.
|
|
68
|
+
|
|
69
|
+
## Deployment Checklist
|
|
70
|
+
|
|
71
|
+
Before sending production traffic, confirm that:
|
|
72
|
+
|
|
73
|
+
- Rails and workers deploy the same application code and queue configuration.
|
|
74
|
+
- Both process types use the same `RAILS_ENV`, Redis endpoint, and queue prefixes.
|
|
75
|
+
- Each required queue definition has an active worker group.
|
|
76
|
+
- Jobs define appropriate Active Job retry and discard behavior for expected failures.
|
|
77
|
+
- Redis persistence and availability match the durability requirements of the application.
|
|
78
|
+
|
|
79
|
+
An inline definition cannot transfer jobs into another process. If a job runs in the web process or never appears in Redis, confirm that the Rails process actually replaced the built-in inline definition.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Queue Configuration
|
|
2
|
+
|
|
3
|
+
This guide explains how to configure `async-job` queue definitions, route Active Jobs, and adopt the adapter incrementally.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Active Job assigns every job a queue name. The adapter must map that name to an `async-job` queue definition, which specifies the processor responsible for storing and running the job.
|
|
8
|
+
|
|
9
|
+
The adapter includes a `default` definition backed by ruby:`Async::Job::Processor::Inline`. Define additional queues when you need:
|
|
10
|
+
|
|
11
|
+
- A shared processor such as Redis instead of in-process execution.
|
|
12
|
+
- Separate capacity for latency-sensitive and bulk workloads.
|
|
13
|
+
- Several Active Job queue names routed through one processor.
|
|
14
|
+
|
|
15
|
+
Every name selected by `queue_as` must have a matching definition or alias.
|
|
16
|
+
|
|
17
|
+
## Defining a Queue
|
|
18
|
+
|
|
19
|
+
Queue definitions belong in `config/initializers/async_job.rb`. The examples below use the Redis processor so independently operated queues have shared storage:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
$ bundle add async-job-processor-redis
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This definition replaces the built-in inline `default` queue:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require "async/job/processor/redis"
|
|
29
|
+
|
|
30
|
+
Rails.application.configure do
|
|
31
|
+
config.async_job.define_queue "default" do
|
|
32
|
+
dequeue Async::Job::Processor::Redis
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Processors can accept positional and keyword arguments after the processor class.
|
|
38
|
+
|
|
39
|
+
## Redis Prefixes
|
|
40
|
+
|
|
41
|
+
Without an explicit `prefix`, every Redis processor uses `async-job`. Queue definition names do not alter that default, so two definitions using the same Redis endpoint and prefix operate on the same underlying queue.
|
|
42
|
+
|
|
43
|
+
For each independently processed queue, the prefix must be:
|
|
44
|
+
|
|
45
|
+
- Distinct from other queues using the same Redis endpoint.
|
|
46
|
+
- Identical in Rails and worker processes.
|
|
47
|
+
- Stable across deployments so existing jobs remain reachable.
|
|
48
|
+
|
|
49
|
+
Include an application or environment namespace only when those workloads share a Redis endpoint.
|
|
50
|
+
|
|
51
|
+
## Defining Multiple Queues
|
|
52
|
+
|
|
53
|
+
Multiple definitions allow independent worker groups to process different workloads. For example, payment capture can use a dedicated queue while ordinary work remains on `default`:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
require "async/job/processor/redis"
|
|
57
|
+
|
|
58
|
+
Rails.application.configure do
|
|
59
|
+
config.async_job.define_queue "default" do
|
|
60
|
+
dequeue Async::Job::Processor::Redis, prefix: "async-job:default"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
config.async_job.define_queue "critical" do
|
|
64
|
+
dequeue Async::Job::Processor::Redis, prefix: "async-job:critical"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Select the definition using the standard Active Job API:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
class PaymentCaptureJob < ApplicationJob
|
|
73
|
+
queue_as :critical
|
|
74
|
+
retry_on PaymentGateway::Unavailable, wait: 5.seconds, attempts: 5
|
|
75
|
+
discard_on ActiveRecord::RecordNotFound
|
|
76
|
+
|
|
77
|
+
def perform(payment_id)
|
|
78
|
+
Payment.find(payment_id).capture!
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Create separate definitions only when workloads need distinct storage, capacity, or operational controls. A single definition is simpler when those differences do not matter.
|
|
84
|
+
|
|
85
|
+
## Aliasing Queue Names
|
|
86
|
+
|
|
87
|
+
Aliases route several Active Job queue names through one queue definition. This is useful for framework-defined names such as `mailers` when they do not need independent worker capacity:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
Rails.application.configure do
|
|
91
|
+
config.async_job.alias_queue "default", "mailers", "low_priority"
|
|
92
|
+
end
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Jobs assigned to `mailers` or `low_priority` are submitted through the `default` definition. Aliases do not create queues and are not valid values for `ASYNC_JOB_ADAPTER_ACTIVE_JOB_QUEUE_NAMES`; worker selection uses definition names.
|
|
96
|
+
|
|
97
|
+
## Opting In One Job at a Time
|
|
98
|
+
|
|
99
|
+
Applications can adopt the adapter without replacing their global Active Job backend. Set `queue_adapter` on an individual job and leave other jobs unchanged:
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
class SearchIndexRefreshJob < ApplicationJob
|
|
103
|
+
self.queue_adapter = :async_job
|
|
104
|
+
queue_as :default
|
|
105
|
+
retry_on SearchIndex::Unavailable, wait: 5.seconds, attempts: 3
|
|
106
|
+
discard_on ActiveRecord::RecordNotFound
|
|
107
|
+
|
|
108
|
+
def perform(product_id)
|
|
109
|
+
Product.find(product_id).refresh_search_index!
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The selected queue must still have a definition or alias in `config.async_job`.
|
|
115
|
+
|
|
116
|
+
## Understanding the Pipeline
|
|
117
|
+
|
|
118
|
+
When `perform_later` is called, ruby:`ActiveJob::QueueAdapters::AsyncJobAdapter` serializes the Active Job and sends it to the definition selected by `queue_as`. The configured processor transports or schedules the payload. On the consumer side, ruby:`Async::Job::Adapter::ActiveJob::Executor` deserializes it and invokes Active Job.
|
|
119
|
+
|
|
120
|
+
Definitions use `async-job`'s pipeline builder. The processor is written as `dequeue` because it wraps the consumer side of the pipeline; it still supplies the client used by Rails to enqueue jobs. The Active Job executor is appended automatically and should not be added to the definition.
|
data/context/testing.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
This guide explains how to test Active Job workloads without running `async-job` queues inline during every test.
|
|
4
|
+
|
|
5
|
+
## Recommended Configuration
|
|
6
|
+
|
|
7
|
+
Configure the adapter for the application in `config/application.rb` so development and production use the same Active Job integration:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
module MyApplication
|
|
11
|
+
class Application < Rails::Application
|
|
12
|
+
config.active_job.queue_adapter = :async_job
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Override the adapter in `config/environments/test.rb`:
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
Rails.application.configure do
|
|
21
|
+
config.active_job.queue_adapter = :test
|
|
22
|
+
end
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The Rails test adapter records enqueued jobs instead of sending them to an `async-job` processor. This keeps tests deterministic, prevents the built-in inline queue from performing jobs unexpectedly, and enables Rails' standard Active Job test helpers.
|
|
26
|
+
|
|
27
|
+
Keeping `:async_job` in the application configuration still exercises the adapter during development. Restricting it to production would make development behave differently from the deployed application.
|
|
28
|
+
|
|
29
|
+
## Testing Job Behavior
|
|
30
|
+
|
|
31
|
+
Use `perform_now` when testing the behavior implemented by a job. This invokes the job directly without involving a queue adapter:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
class SearchIndexRefreshJobTest < ActiveJob::TestCase
|
|
35
|
+
test "refreshes the product index" do
|
|
36
|
+
product = products(:example)
|
|
37
|
+
|
|
38
|
+
assert_changes ->{product.reload.indexed_at} do
|
|
39
|
+
SearchIndexRefreshJob.perform_now(product.id)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Testing Enqueueing
|
|
46
|
+
|
|
47
|
+
Use `assert_enqueued_with` to verify that application code submits the expected job and arguments:
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
class ProductTest < ActiveSupport::TestCase
|
|
51
|
+
include ActiveJob::TestHelper
|
|
52
|
+
|
|
53
|
+
test "schedules an index refresh" do
|
|
54
|
+
product = products(:example)
|
|
55
|
+
|
|
56
|
+
assert_enqueued_with(job: SearchIndexRefreshJob, args: [product.id]) do
|
|
57
|
+
product.schedule_index_refresh
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Rails also provides `assert_enqueued_jobs` when only the number of submitted jobs matters.
|
|
64
|
+
|
|
65
|
+
## Performing Enqueued Jobs
|
|
66
|
+
|
|
67
|
+
Use `perform_enqueued_jobs` when a test needs to exercise the code that enqueues a job and the job itself:
|
|
68
|
+
|
|
69
|
+
```ruby
|
|
70
|
+
class ProductTest < ActiveSupport::TestCase
|
|
71
|
+
include ActiveJob::TestHelper
|
|
72
|
+
|
|
73
|
+
test "refreshes the index asynchronously" do
|
|
74
|
+
product = products(:example)
|
|
75
|
+
|
|
76
|
+
perform_enqueued_jobs do
|
|
77
|
+
product.schedule_index_refresh
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
assert product.reload.indexed_at
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The helper performs jobs captured by the Rails test adapter within the block. It does not start an `async-job` processor or worker.
|
|
86
|
+
|
|
87
|
+
## Testing Production Queue Integration
|
|
88
|
+
|
|
89
|
+
Tests using `:test` verify job behavior and enqueueing through Active Job, but they do not exercise the production queue transport. Cover Redis-backed definitions and separate workers with a focused integration or deployment smoke test using the same queue configuration as production.
|
|
90
|
+
|
|
91
|
+
Such a test should submit a uniquely identifiable job, wait for a worker to consume it, and verify its externally visible result. Keep this separate from the unit test suite so ordinary tests do not depend on Redis, worker timing, or another process.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2024-
|
|
4
|
+
# Copyright, 2024-2026, by Samuel Williams.
|
|
5
5
|
|
|
6
6
|
require_relative "executor"
|
|
7
7
|
|
|
@@ -61,6 +61,8 @@ module Async
|
|
|
61
61
|
@definitions.keys
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
# Generate a summary of the configured queues and their server status.
|
|
65
|
+
# @returns [String] A comma-separated summary of all configured queues.
|
|
64
66
|
def status_string
|
|
65
67
|
self.keys.map do |name|
|
|
66
68
|
queue = @queues[name]
|
|
@@ -48,7 +48,7 @@ module Async
|
|
|
48
48
|
Console.debug(self, "Starting queue...", queue_name: queue_name)
|
|
49
49
|
dispatcher.start(queue_name)
|
|
50
50
|
rescue => error
|
|
51
|
-
Console
|
|
51
|
+
Console.error(self, "Failed to start queue!", queue_name: queue_name, exception: error)
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
data/readme.md
CHANGED
|
@@ -8,7 +8,13 @@ Provides an adapter for ActiveJob on top of `Async::Job`.
|
|
|
8
8
|
|
|
9
9
|
Please see the [project documentation](https://socketry.github.io/async-job-adapter-active_job/) for more details.
|
|
10
10
|
|
|
11
|
-
- [Getting Started](https://socketry.github.io/async-job-adapter-active_job/guides/getting-started/index) - This guide explains how to
|
|
11
|
+
- [Getting Started](https://socketry.github.io/async-job-adapter-active_job/guides/getting-started/index) - This guide explains how to use `async-job-adapter-active_job` to run Rails Active Job workloads with inline or Redis-backed queues.
|
|
12
|
+
|
|
13
|
+
- [Testing](https://socketry.github.io/async-job-adapter-active_job/guides/testing/index) - This guide explains how to test Active Job workloads without running `async-job` queues inline during every test.
|
|
14
|
+
|
|
15
|
+
- [Production Deployment](https://socketry.github.io/async-job-adapter-active_job/guides/production-deployment/index) - This guide explains how to deploy `async-job-adapter-active_job` with Redis-backed queues and separate worker processes.
|
|
16
|
+
|
|
17
|
+
- [Queue Configuration](https://socketry.github.io/async-job-adapter-active_job/guides/queue-configuration/index) - This guide explains how to configure `async-job` queue definitions, route Active Jobs, and adopt the adapter incrementally.
|
|
12
18
|
|
|
13
19
|
## Releases
|
|
14
20
|
|
|
@@ -64,26 +70,26 @@ Please see the [project releases](https://socketry.github.io/async-job-adapter-a
|
|
|
64
70
|
|
|
65
71
|
We welcome contributions to this project.
|
|
66
72
|
|
|
67
|
-
1. Fork
|
|
73
|
+
1. Fork the repository.
|
|
68
74
|
2. Create your feature branch (`git checkout -b my-new-feature`).
|
|
69
|
-
3. Commit your changes (`git commit -am 'Add some feature'`).
|
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature.'`).
|
|
70
76
|
4. Push to the branch (`git push origin my-new-feature`).
|
|
71
|
-
5. Create new
|
|
77
|
+
5. Create a new pull request.
|
|
72
78
|
|
|
73
79
|
### Running Tests
|
|
74
80
|
|
|
75
81
|
To run the test suite:
|
|
76
82
|
|
|
77
|
-
```
|
|
78
|
-
bundle exec sus
|
|
83
|
+
``` bash
|
|
84
|
+
$ bundle exec sus
|
|
79
85
|
```
|
|
80
86
|
|
|
81
87
|
### Making Releases
|
|
82
88
|
|
|
83
89
|
To make a new release:
|
|
84
90
|
|
|
85
|
-
```
|
|
86
|
-
bundle exec bake gem:release:patch # or minor or major
|
|
91
|
+
``` bash
|
|
92
|
+
$ bundle exec bake gem:release:patch # or minor or major
|
|
87
93
|
```
|
|
88
94
|
|
|
89
95
|
### Developer Certificate of Origin
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: async-job-adapter-active_job
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.20.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samuel Williams
|
|
@@ -92,6 +92,9 @@ files:
|
|
|
92
92
|
- bin/async-job-adapter-active_job-server
|
|
93
93
|
- context/getting-started.md
|
|
94
94
|
- context/index.yaml
|
|
95
|
+
- context/production-deployment.md
|
|
96
|
+
- context/queue-configuration.md
|
|
97
|
+
- context/testing.md
|
|
95
98
|
- lib/active_job/queue_adapters/async_job_adapter.rb
|
|
96
99
|
- lib/async/job/adapter/active_job.rb
|
|
97
100
|
- lib/async/job/adapter/active_job/dispatcher.rb
|
|
@@ -108,6 +111,8 @@ homepage: https://github.com/socketry/async-job-adapter-active_job
|
|
|
108
111
|
licenses:
|
|
109
112
|
- MIT
|
|
110
113
|
metadata:
|
|
114
|
+
bug_tracker_uri: https://github.com/socketry/async-job-adapter-active_job/issues
|
|
115
|
+
changelog_uri: https://github.com/socketry/async-job-adapter-active_job/blob/main/releases.md
|
|
111
116
|
documentation_uri: https://socketry.github.io/async-job-adapter-active_job/
|
|
112
117
|
source_code_uri: https://github.com/socketry/async-job-adapter-active_job.git
|
|
113
118
|
rdoc_options: []
|
|
@@ -124,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
124
129
|
- !ruby/object:Gem::Version
|
|
125
130
|
version: '0'
|
|
126
131
|
requirements: []
|
|
127
|
-
rubygems_version:
|
|
132
|
+
rubygems_version: 4.0.10
|
|
128
133
|
specification_version: 4
|
|
129
134
|
summary: A asynchronous job queue for Ruby on Rails.
|
|
130
135
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|