Async::Job::Adapter::AsyncJobSourceAsyncJobAdapterActiveJobDispatcher

class Dispatcher

A dispatcher for managing multiple definitions.

Definitions

def initialize(definitions = {}, aliases = {})

Prepare the dispacher with the given definitions and aliases.

Signature

parameter definitions Hash(String, Proc)

The definitions to use constructing queues.

parameter aliases Hash(String, Proc)

The aliases for the definitions.

Implementation

def initialize(definitions = {}, aliases = {})
	@definitions = definitions
	@aliases = aliases
	
	@queues = {}
end

attr :definitions

Signature

attribute Hash(String, Proc)

The definitions to use for processing jobs.

attr :aliases

Signature

attribute Hash(String, String)

The aliases for the definitions.

attr :queues

Signature

attribute Hash(String, Queue)

The queues that have been constructed.

def [](name)

Look up a queue by name, constructing it if necessary using the given definition.

Signature

parameter name String

The name of the queue.

Implementation

def [](name)
	@queues.fetch(name) do
		definition = @definitions.fetch(name)
		@queues[name] = build(definition)
	end
end

def call(job)

Dispatch a job to the appropriate queue.

Signature

parameter job ActiveJob::Base

The job to dispatch.

Implementation

def call(job)
	name = @aliases.fetch(job.queue_name, job.queue_name)
	
	self[name].client.call(job.serialize)
end

def start(name)

Start processing jobs in the given queue.

Implementation

def start(name)
	self[name].server.start
end

def keys

Get the names of all available queue definitions.

Signature

returns Array<String>

The queue definition names.

Implementation

def keys
	@definitions.keys
end