File tree Expand file tree Collapse file tree 7 files changed +38
-0
lines changed
active_job/queue_adapters Expand file tree Collapse file tree 7 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 7
7
8
8
require "kernel/sync"
9
9
10
+ # @namespace
10
11
module ActiveJob
12
+ # @namespace
11
13
module QueueAdapters
14
+ # ActiveJob adapter for async-job, providing asynchronous job processing capabilities.
12
15
class AsyncJobAdapter < AbstractAdapter
16
+ # Initialize the adapter with a dispatcher.
17
+ # @parameter dispatcher [Object] The job dispatcher, defaults to the Railtie dispatcher.
13
18
def initialize ( dispatcher = ::Async ::Job ::Adapter ::ActiveJob ::Railtie . dispatcher )
14
19
@dispatcher = dispatcher
15
20
end
Original file line number Diff line number Diff line change 10
10
require_relative "active_job/railtie"
11
11
require "active_job/queue_adapters/async_job_adapter"
12
12
end
13
+
14
+ # @namespace
15
+ module Async
16
+ # @namespace
17
+ module Job
18
+ # @namespace
19
+ module Adapter
20
+ # @namespace
21
+ module ActiveJob
22
+ end
23
+ end
24
+ end
25
+ end
Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ def [](name)
42
42
end
43
43
end
44
44
45
+ # Dispatch a job to the appropriate queue.
46
+ # @parameter job [ActiveJob::Base] The job to dispatch.
45
47
def call ( job )
46
48
name = @aliases . fetch ( job . queue_name , job . queue_name )
47
49
@@ -53,6 +55,8 @@ def start(name)
53
55
self [ name ] . server . start
54
56
end
55
57
58
+ # Get the names of all available queue definitions.
59
+ # @returns [Array<String>] The queue definition names.
56
60
def keys
57
61
@definitions . keys
58
62
end
Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ def root
22
22
ENV . fetch ( "RAILS_ROOT" , Dir . pwd )
23
23
end
24
24
25
+ # Get the default dispatcher instance.
26
+ # @returns [Object] The dispatcher from the Railtie.
25
27
def dispatcher
26
28
Railtie . dispatcher
27
29
end
Original file line number Diff line number Diff line change @@ -17,10 +17,14 @@ module Adapter
17
17
module ActiveJob
18
18
# An executor for processing jobs using `ActiveJob`.
19
19
class Executor
20
+ # Initialize the executor with an optional delegate.
21
+ # @parameter delegate [Object] An optional delegate object for handling lifecycle methods.
20
22
def initialize ( delegate = nil )
21
23
@delegate = delegate
22
24
end
23
25
26
+ # Execute a job with the given data.
27
+ # @parameter job_data [Hash] Serialized job data from ActiveJob.
24
28
def execute ( job_data )
25
29
::ActiveJob ::Callbacks . run_callbacks ( :execute ) do
26
30
job = ::ActiveJob ::Base . deserialize ( job_data )
@@ -46,10 +50,12 @@ def call(job)
46
50
@delegate &.call ( job )
47
51
end
48
52
53
+ # Start the delegate if present.
49
54
def start
50
55
@delegate &.start
51
56
end
52
57
58
+ # Stop the delegate if present.
53
59
def stop
54
60
@delegate &.stop
55
61
end
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ class Railtie < ::Rails::Railtie
19
19
dequeue Processor ::Inline
20
20
end
21
21
22
+ # Initialize the railtie with default queue configuration.
22
23
def initialize
23
24
@definitions = { "default" => DEFAULT_QUEUE_DEFINITION }
24
25
@aliases = { }
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ module Adapter
13
13
module ActiveJob
14
14
# Used for dispatching jobs to a thread-local queue to avoid thread-safety issues.
15
15
class ThreadLocalDispatcher
16
+ # Initialize with queue definitions and aliases.
17
+ # @parameter definitions [Hash] The queue definitions.
18
+ # @parameter aliases [Hash] The queue aliases.
16
19
def initialize ( definitions , aliases )
17
20
@definitions = definitions
18
21
@aliases = aliases
@@ -31,10 +34,14 @@ def dispatcher
31
34
Thread . current . async_job_adapter_active_job_dispatcher ||= Dispatcher . new ( @definitions , @aliases )
32
35
end
33
36
37
+ # Get a queue by name.
38
+ # @parameter name [String] The queue name.
34
39
def []( name )
35
40
dispatcher [ name ]
36
41
end
37
42
43
+ # Dispatch a job using the thread-local dispatcher.
44
+ # @parameter job [ActiveJob::Base] The job to dispatch.
38
45
def call ( job )
39
46
dispatcher . call ( job )
40
47
end
You can’t perform that action at this time.
0 commit comments