Async::JobSourceAsyncJobBuilder

class Builder

Represents a builder for creating job processing pipelines. The builder allows you to configure middleware for both enqueue and dequeue operations, creating a complete job processing system with client and server components.

Definitions

def self.build(delegate = nil, &block)

Build a job processing pipeline using the provided delegate and configuration block.

Signature

parameter delegate Object | nil

The delegate that will execute the jobs.

yields {|builder| ...}

The builder instance for configuration.

returns Async::Job::Queue

A configured job queue with client and server components.

Implementation

def self.build(delegate = nil, &block)
	builder = self.new(delegate)
	
	builder.instance_eval(&block)
	
	return builder.build
end

def build(delegate = @delegate)

Build the final job processing pipeline.

Signature

parameter delegate Object

The delegate to use (defaults to the instance delegate).

returns Async::Job::Queue

A configured job queue.

Implementation

def build(delegate = @delegate)
	# We then wrap the delegate with the middleware in reverse order:
	@dequeue.reverse_each do |middleware|
		delegate = middleware.call(delegate)
	end
	
	client = server = delegate
	
	# We now construct the queue producer:
	@enqueue.reverse_each do |middleware|
		client = middleware.call(client)
	end
	
	return Queue.new(client, server, @delegate)
end

def initialize(delegate = nil)

Initialize a new job builder.

Signature

parameter delegate Object

The initial delegate that will be wrapped by the queue.

Implementation

def initialize(delegate = nil)
	# The client side middleware, in the order they should be applied to a job:
	@enqueue = []
	
	# The server side middleware, in the order they should be applied to a job:
	@dequeue = []
	
	# The output delegate, if any:
	@delegate = delegate
end

def enqueue(middleware, ...)

Add middleware to the enqueue pipeline.

Signature

parameter middleware Class

The middleware class to add.

Implementation

def enqueue(middleware, ...)
	@enqueue << ->(delegate){middleware.new(delegate, ...)}

	return self
end

def dequeue(middleware, ...)

Add middleware to the dequeue pipeline.

Signature

parameter middleware Class

The middleware class to add.

Implementation

def dequeue(middleware, ...)
	@dequeue << ->(delegate){middleware.new(delegate, ...)}

	return self
end

def delegate(delegate)

Set the delegate that will execute the jobs.

Signature

parameter delegate Object

The delegate object.

Implementation

def delegate(delegate)
	@delegate = delegate

	return self
end