Module: Servus::Extensions::Async::Call
- Defined in:
- lib/servus/extensions/async/call.rb
Overview
Provides asynchronous service execution via ActiveJob.
This module extends Base with the #call_async method, enabling services to be executed in background jobs. Requires ActiveJob to be loaded.
Instance Method Summary collapse
-
#call_async(**args) ⇒ void
Enqueues the service for asynchronous execution via ActiveJob.
Instance Method Details
#call_async(**args) ⇒ void
Only available when ActiveJob is loaded (typically in Rails applications)
This method returns an undefined value.
Enqueues the service for asynchronous execution via ActiveJob.
This method schedules the service to run in a background job, supporting all standard ActiveJob options for scheduling, queue routing, and priority.
Service arguments are passed as keyword arguments alongside job configuration. Job-specific options are extracted and the remaining arguments are passed to the service's initialize method.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/servus/extensions/async/call.rb', line 60 def call_async(**args) # Extract ActiveJob configuration options = args.slice(:wait, :wait_until, :queue, :priority) .merge!(args.delete(:job_options) || {}) # merge custom job options # Remove special keys that shouldn't be passed to the service args.except!(:wait, :wait_until, :queue, :priority, :job_options) # Build job with optional delay, scheduling, or queue settings job = .any? ? Job.set(**.compact) : Job # Enqueue the job asynchronously job.perform_later(name: name, args: args) rescue StandardError => e raise Errors::JobEnqueueError, "Failed to enqueue async job for #{self}: #{e.message}" end |