feat(lifecycle): implement DispatcherJob
Replace no-op stub with full perform body: find delivery by id, skip if blank, delegate to Captain::Lifecycle::Dispatcher#call. Add retry_on with polynomially_longer backoff (3 attempts). Spec covers dispatcher delegation and graceful skip for missing records. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0d4583a21a
commit
d0d08ed662
@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
class Captain::Lifecycle::DispatcherJob < ApplicationJob
|
class Captain::Lifecycle::DispatcherJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
retry_on StandardError, wait: :polynomially_longer, attempts: 3
|
||||||
|
|
||||||
def self.perform_at(fire_at, delivery_id)
|
def self.perform_at(fire_at, delivery_id)
|
||||||
set(wait_until: fire_at).perform_later(delivery_id)
|
set(wait_until: fire_at).perform_later(delivery_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform(delivery_id)
|
def perform(delivery_id)
|
||||||
# Stub — full implementation lands in Task 16.
|
delivery = Captain::Lifecycle::Delivery.find_by(id: delivery_id)
|
||||||
|
return if delivery.blank?
|
||||||
|
|
||||||
|
Captain::Lifecycle::Dispatcher.new(delivery).call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Captain::Lifecycle::DispatcherJob do
|
||||||
|
let(:delivery) { create(:captain_lifecycle_delivery) }
|
||||||
|
|
||||||
|
it 'calls Dispatcher#call' do
|
||||||
|
dispatcher = instance_double(Captain::Lifecycle::Dispatcher)
|
||||||
|
expect(Captain::Lifecycle::Dispatcher)
|
||||||
|
.to receive(:new)
|
||||||
|
.with(instance_of(Captain::Lifecycle::Delivery))
|
||||||
|
.and_return(dispatcher)
|
||||||
|
expect(dispatcher).to receive(:call)
|
||||||
|
|
||||||
|
described_class.perform_now(delivery.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'silently skips missing delivery records' do
|
||||||
|
expect { described_class.perform_now(-1) }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user