Class: Zeridion::Flare::Worker::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/zeridion_flare/worker/executor.rb

Overview

Executes a single polled job: resolves its definition, decodes the payload, builds the JobContext, invokes #perform, and reports the outcome. Mirrors the reference SDK's JobExecutor.

Ack-status mapping (decision D1): a normal return → "succeeded"; ANY raised exception — including cancellation, timeout, or an unknown job type — → "failed". The worker NEVER acks "cancelled". The error.type is the exception's class name (one-level cause-unwrap), matching the reference's fully-qualified error type.

Defined Under Namespace

Classes: Outcome

Instance Method Summary collapse

Constructor Details

#initialize(registry:, logger: nil) ⇒ Executor

Returns a new instance of Executor.



24
25
26
27
# File 'lib/zeridion_flare/worker/executor.rb', line 24

def initialize(registry:, logger: nil)
  @registry = registry
  @logger = logger
end

Instance Method Details

#execute(item, context) ⇒ Outcome

Parameters:

  • item (Hash)

    the polled job item (string keys: "id", "job_type", "payload", "attempt", "max_attempts", "timeout_seconds", "enqueued_at")

  • context (JobContext)

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/zeridion_flare/worker/executor.rb', line 33

def execute(item, context)
  definition = @registry.lookup(item["job_type"])
  if definition.nil?
    return Outcome.new(
      succeeded: false,
      error: error_hash(UnknownJobTypeError.new(item["job_type"])),
    )
  end

  begin
    invoke(definition, item, context)
    Outcome.new(succeeded: true, error: nil)
  rescue StandardError => e
    Outcome.new(succeeded: false, error: error_hash(unwrap(e)))
  end
end