Async::JobSourceAsyncJobProcessorInline

class Inline

Represents an inline processor that executes jobs asynchronously using Async::Idler. This processor handles job scheduling and executes jobs in the background, providing a simple way to process jobs without external dependencies.

Definitions

def initialize(delegate, parent: nil)

Initialize a new inline processor.

Signature

parameter delegate Object

The delegate object that will handle job execution.

option parent Async::Idler

The parent idler for managing async tasks (defaults to a new Async::Idler).

Implementation

def initialize(delegate, parent: nil)
	super(delegate)
	
	@parent = parent || Async::Idler.new
end

def call(job)

Process a job asynchronously with optional scheduling. If the job has a scheduled_at time, the processor will wait until that time before execution.

Signature

parameter job Hash

The job data containing execution details.

Implementation

def call(job)
	scheduled_at = Coder::Time(job["scheduled_at"])
	
	@parent.async do
		if scheduled_at
			sleep(scheduled_at - Time.now)
		end
		
		@delegate.call(job)
	rescue => error
		Console.error(self, error)
	end
end

def start

Start the processor by delegating to the configured delegate.

Implementation

def start
	@delegate.start
end

def stop

Stop the processor by delegating to the configured delegate.

Implementation

def stop
	@delegate.stop
end