Module: Statecraft::Instrumentation
- Defined in:
- lib/statecraft/instrumentation.rb
Overview
Publishes the two ActiveSupport::Notifications events of the pipeline. Success and refusal need different event names, so timing is measured manually and published with explicit start/finish instead of a naive instrument block. Metadata never enters a payload: subscribers routinely log payloads whole, and metadata is the one place PII can live — whoever needs it reads the log record. Refusal events are published after the savepoint rollback, outside the transaction, so a subscriber writing to the database is never rolled back together with the pipeline.
Constant Summary collapse
- TRANSITION_EVENT =
"transition.statecraft"- FAILURE_EVENT =
"transition_failed.statecraft"
Class Method Summary collapse
- .publish_failure(started_at:, record:, machine_class:, reason:, details:) ⇒ Object
- .publish_transition(started_at:, record:, machine_class:, log_record:) ⇒ Object
Class Method Details
.publish_failure(started_at:, record:, machine_class:, reason:, details:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/statecraft/instrumentation.rb', line 28 def self.publish_failure(started_at:, record:, machine_class:, reason:, details:) publish( FAILURE_EVENT, started_at, { record_class: record.class.base_class.name, record_id: record.id, machine: machine_class.name, reason: reason }.merge(details) ) end |
.publish_transition(started_at:, record:, machine_class:, log_record:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/statecraft/instrumentation.rb', line 16 def self.publish_transition(started_at:, record:, machine_class:, log_record:) publish( TRANSITION_EVENT, started_at, record_class: record.class.base_class.name, record_id: record.id, machine: machine_class.name, from: log_record.from_state.to_sym, to: log_record.to_state.to_sym, event: log_record.event&.to_sym ) end |