Class: Railsmith::AsyncNestedWriteJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Railsmith::AsyncNestedWriteJob
- Defined in:
- lib/railsmith/async_nested_write_job.rb
Overview
Default ActiveJob base class for async nested association writes.
Enabled by declaring an association with async: true and wiring this job (or any ActiveJob subclass with a compatible #perform signature) into configuration:
# config/initializers/railsmith.rb
Railsmith.configure do |c|
c.async_job_class = Railsmith::AsyncNestedWriteJob
end
The job re-hydrates the original service and re-invokes the nested write for the named association on a fresh parent record. Because the parent transaction has already committed by the time the job runs, failures here cannot roll back the parent — retries are handled via ActiveJob’s standard retry / dead-letter machinery, and terminal failures emit an async_nested_write.failed.railsmith event so the app can alert.
Instance Method Summary collapse
Instance Method Details
#perform(service_class:, association:, parent_id:, nested_params:, mode:, context:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/railsmith/async_nested_write_job.rb', line 25 def perform(service_class:, association:, parent_id:, nested_params:, mode:, context:) with_instrumented_failure(**failure_context(service_class, association, parent_id, mode)) do result = perform_nested_write( service_class: service_class, association: association, parent_id: parent_id, nested_params: nested_params, mode: mode, context: context ) raise_if_failure_result(result) result end end |