Module: Servus::Extensions::Async

Defined in:
lib/servus/extensions/async/ext.rb,
lib/servus/extensions/async/job.rb,
lib/servus/extensions/async/call.rb,
lib/servus/extensions/async/errors.rb

Overview

Asynchronous execution extensions for Servus services.

This module provides the infrastructure for running services in background jobs via ActiveJob. When loaded, it extends Base with the Call#call_async method.

See Also:

Defined Under Namespace

Modules: Call, Errors, Ext Classes: Job

Class Method Summary collapse

Class Method Details

.install! ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Installs async support on Base and backfills job classes for services that were already defined.

The backfill exists because Servus::Extensions::Async::Call#inherited — which publishes a service's job constant — only exists once this module is installed, and installation is deferred to on_load(:active_job). Servus's own railtie force-loads app/events/*_event.rb, and every service named by an enqueue there loads with it, typically before anything has touched ActiveJob::Base. Those services would otherwise never publish a job constant, and a worker — which resolves jobs by name and never calls Servus::Extensions::Async::Call#call_async — would fail deserialization with ActiveJob::UnknownJobClassError.

Only services still reachable under their own name are backfilled. An anonymous service has no constant to publish, and a class whose name no longer resolves to it — replaced by a reload, or defined under a namespace that has since gone — has nothing to publish it under either.



45
46
47
48
49
50
51
# File 'lib/servus/extensions/async/ext.rb', line 45

def self.install!
  Servus::Base.extend(Call)

  Servus::Base.descendants.each do |service|
    service.servus_job_class if service.name&.safe_constantize.equal?(service)
  end
end