Skip to content

Commit 71e5b2f

Browse files
100% documentation coverage.
1 parent 430963b commit 71e5b2f

File tree

7 files changed

+38
-0
lines changed

7 files changed

+38
-0
lines changed

lib/active_job/queue_adapters/async_job_adapter.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77

88
require "kernel/sync"
99

10+
# @namespace
1011
module ActiveJob
12+
# @namespace
1113
module QueueAdapters
14+
# ActiveJob adapter for async-job, providing asynchronous job processing capabilities.
1215
class AsyncJobAdapter < AbstractAdapter
16+
# Initialize the adapter with a dispatcher.
17+
# @parameter dispatcher [Object] The job dispatcher, defaults to the Railtie dispatcher.
1318
def initialize(dispatcher = ::Async::Job::Adapter::ActiveJob::Railtie.dispatcher)
1419
@dispatcher = dispatcher
1520
end

lib/async/job/adapter/active_job.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,16 @@
1010
require_relative "active_job/railtie"
1111
require "active_job/queue_adapters/async_job_adapter"
1212
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

lib/async/job/adapter/active_job/dispatcher.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def [](name)
4242
end
4343
end
4444

45+
# Dispatch a job to the appropriate queue.
46+
# @parameter job [ActiveJob::Base] The job to dispatch.
4547
def call(job)
4648
name = @aliases.fetch(job.queue_name, job.queue_name)
4749

@@ -53,6 +55,8 @@ def start(name)
5355
self[name].server.start
5456
end
5557

58+
# Get the names of all available queue definitions.
59+
# @returns [Array<String>] The queue definition names.
5660
def keys
5761
@definitions.keys
5862
end

lib/async/job/adapter/active_job/environment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def root
2222
ENV.fetch("RAILS_ROOT", Dir.pwd)
2323
end
2424

25+
# Get the default dispatcher instance.
26+
# @returns [Object] The dispatcher from the Railtie.
2527
def dispatcher
2628
Railtie.dispatcher
2729
end

lib/async/job/adapter/active_job/executor.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ module Adapter
1717
module ActiveJob
1818
# An executor for processing jobs using `ActiveJob`.
1919
class Executor
20+
# Initialize the executor with an optional delegate.
21+
# @parameter delegate [Object] An optional delegate object for handling lifecycle methods.
2022
def initialize(delegate = nil)
2123
@delegate = delegate
2224
end
2325

26+
# Execute a job with the given data.
27+
# @parameter job_data [Hash] Serialized job data from ActiveJob.
2428
def execute(job_data)
2529
::ActiveJob::Callbacks.run_callbacks(:execute) do
2630
job = ::ActiveJob::Base.deserialize(job_data)
@@ -46,10 +50,12 @@ def call(job)
4650
@delegate&.call(job)
4751
end
4852

53+
# Start the delegate if present.
4954
def start
5055
@delegate&.start
5156
end
5257

58+
# Stop the delegate if present.
5359
def stop
5460
@delegate&.stop
5561
end

lib/async/job/adapter/active_job/railtie.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Railtie < ::Rails::Railtie
1919
dequeue Processor::Inline
2020
end
2121

22+
# Initialize the railtie with default queue configuration.
2223
def initialize
2324
@definitions = {"default" => DEFAULT_QUEUE_DEFINITION}
2425
@aliases = {}

lib/async/job/adapter/active_job/thread_local_dispatcher.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ module Adapter
1313
module ActiveJob
1414
# Used for dispatching jobs to a thread-local queue to avoid thread-safety issues.
1515
class ThreadLocalDispatcher
16+
# Initialize with queue definitions and aliases.
17+
# @parameter definitions [Hash] The queue definitions.
18+
# @parameter aliases [Hash] The queue aliases.
1619
def initialize(definitions, aliases)
1720
@definitions = definitions
1821
@aliases = aliases
@@ -31,10 +34,14 @@ def dispatcher
3134
Thread.current.async_job_adapter_active_job_dispatcher ||= Dispatcher.new(@definitions, @aliases)
3235
end
3336

37+
# Get a queue by name.
38+
# @parameter name [String] The queue name.
3439
def [](name)
3540
dispatcher[name]
3641
end
3742

43+
# Dispatch a job using the thread-local dispatcher.
44+
# @parameter job [ActiveJob::Base] The job to dispatch.
3845
def call(job)
3946
dispatcher.call(job)
4047
end

0 commit comments

Comments
 (0)