class ThreadLocalDispatcher
Used for dispatching jobs to a thread-local queue to avoid thread-safety issues.
Definitions
attr :definitions
Signature
-
attribute
Hash(String, Proc)
The definitions to use for creating queues.
attr :aliases
Signature
-
attribute
Hash(String, String)
The aliases for the job queues.
def dispatcher
The dispatcher for the current thread.
As a dispatcher contains state, it is important to ensure that each thread has its own dispatcher.
Implementation
def dispatcher
Thread.current.async_job_adapter_active_job_dispatcher ||= Dispatcher.new(@definitions, @aliases)
end
def start(name)
Start processing jobs in the queue with the given name.
Signature
-
parameter
name
String
The name of the queue.
Implementation
def start(name)
dispatcher.start(name)
end
def keys
The names of all the queues that are available for processing jobs.
Implementation
def keys
@definitions.keys
end