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
	
	@call_count = 0
	@complete_count = 0
	@failed_count = 0
end

attr_reader :call_count

Signature

attribute Integer

The current number of in-progress jobs.

attr_reader :complete_count

Signature

attribute Integer

The count of completed jobs.

attr_reader :failed_count

Signature

attribute Integer

The count of failed jobs.

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
		
		@call_count += 1
		@delegate.call(job)
		@complete_count += 1
	rescue => error
		@failed_count += 1
		Console.error(self, error)
	ensure
		@call_count -= 1
	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

def status_string

Returns statistics about the processor's job counts.

  • c: call count / completed count.

Implementation

def status_string
	"C=#{String::Format.count(@call_count)}/#{String::Format.count(@complete_count)} F=#{String::Format.count(@failed_count)}"
end