Class: OmniService::Async

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Defined in:
lib/omni_service/async.rb

Overview

Wraps operation execution in a background job (ActiveJob). Returns immediately with Success(job_id: …) instead of operation result.

Examples:

Direct usage

async = OmniService::Async.new(Posts::Create, :system, job_class: PostJob)
async.call({ title: 'Hello' }, author: user)
# => Success(job_id: 'abc-123')

Via Convenience module (recommended)

class Posts::Create
  extend OmniService::Convenience
  extend OmniService::Async::Convenience[queue: 'default', retry: 3]

  def self.system
    @system ||= sequence(validate_params, create_post)
  end
end

Posts::Create.system_async.call({ title: 'Hello' }, author: user)

Defined Under Namespace

Modules: Convenience

Instance Method Summary collapse

Instance Method Details

#call(*params, **context) ⇒ Object



102
103
104
105
# File 'lib/omni_service/async.rb', line 102

def call(*params, **context)
  job = job_class.set(job_options).perform_later(container_class, container_method, params, context)
  Success(job_id: job.provider_job_id)
end