Class: Mammoth::Application
- Inherits:
-
Object
- Object
- Mammoth::Application
- Defined in:
- lib/mammoth/application.rb
Overview
Top-level Mammoth application runtime.
Application wires Mammoth's delivery-side runtime pieces: configuration, operational-state adapter, replication consumer, delivery worker, checkpoint store, dead-letter store, and webhook sink. Upstream PostgreSQL transport composition stays outside this class so the application runtime consumes an injected CDC work source rather than owning upstream CDC source-adapter lifecycle decisions. rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#checkpoint_store ⇒ Object
readonly
Returns the value of attribute checkpoint_store.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
-
#delivery_worker ⇒ Object
readonly
Returns the value of attribute delivery_worker.
-
#lifecycle_hooks ⇒ Object
readonly
Returns the value of attribute lifecycle_hooks.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#observer ⇒ Object
readonly
Returns the value of attribute observer.
-
#progress_coordinator ⇒ Object
readonly
Returns the value of attribute progress_coordinator.
-
#state_adapter ⇒ Object
readonly
Returns the value of attribute state_adapter.
Instance Method Summary collapse
-
#initialize(config, source: nil, sink: nil, state_adapter: nil, sleeper: Kernel.method(:sleep), lifecycle_hooks: LifecycleHooks.new, observer: nil, logger: nil) ⇒ Application
constructor
A new instance of Application.
-
#sqlite_store ⇒ Mammoth::SQLiteStore
Underlying SQLite store for compatibility.
-
#start ⇒ Integer
Start the application runtime and deliver consumed CDC work.
Constructor Details
#initialize(config, source: nil, sink: nil, state_adapter: nil, sleeper: Kernel.method(:sleep), lifecycle_hooks: LifecycleHooks.new, observer: nil, logger: nil) ⇒ Application
Returns a new instance of Application.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mammoth/application.rb', line 25 def initialize(config, source: nil, sink: nil, state_adapter: nil, sleeper: Kernel.method(:sleep), lifecycle_hooks: LifecycleHooks.new, observer: nil, logger: nil) @config = config @logger = logger || Logging.build(config) @lifecycle_hooks = build_lifecycle_hooks(lifecycle_hooks) @observer = observer || MetricsObserver.new @state_adapter = state_adapter || build_state_adapter @checkpoint_store = @state_adapter.checkpoint_store @consumer = ReplicationConsumer.new(source: source || build_source, delivery_unit: delivery_unit) @progress_coordinator = build_progress_coordinator @delivery_worker = if sink build_delivery_worker( sink: sink, sleeper: sleeper, delivery_policy: destination_delivery_policy(config.data["webhook"] || {}) ) else build_configured_delivery_worker(sleeper: sleeper) end end |
Instance Attribute Details
#checkpoint_store ⇒ Object (readonly)
Returns the value of attribute checkpoint_store.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def checkpoint_store @checkpoint_store end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def config @config end |
#consumer ⇒ Object (readonly)
Returns the value of attribute consumer.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def consumer @consumer end |
#delivery_worker ⇒ Object (readonly)
Returns the value of attribute delivery_worker.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def delivery_worker @delivery_worker end |
#lifecycle_hooks ⇒ Object (readonly)
Returns the value of attribute lifecycle_hooks.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def lifecycle_hooks @lifecycle_hooks end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def logger @logger end |
#observer ⇒ Object (readonly)
Returns the value of attribute observer.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def observer @observer end |
#progress_coordinator ⇒ Object (readonly)
Returns the value of attribute progress_coordinator.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def progress_coordinator @progress_coordinator end |
#state_adapter ⇒ Object (readonly)
Returns the value of attribute state_adapter.
14 15 16 |
# File 'lib/mammoth/application.rb', line 14 def state_adapter @state_adapter end |
Instance Method Details
#sqlite_store ⇒ Mammoth::SQLiteStore
Returns underlying SQLite store for compatibility.
47 48 49 |
# File 'lib/mammoth/application.rb', line 47 def sqlite_store state_adapter.respond_to?(:sqlite_store) ? state_adapter.sqlite_store : nil end |
#start ⇒ Integer
Start the application runtime and deliver consumed CDC work.
rubocop:disable Metrics/AbcSize
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mammoth/application.rb', line 55 def start runtime = build_runtime processed = nil operational_logger.info("application_started", mammoth_name: config&.dig("mammoth", "name"), runtime: config&.dig("runtime", "adapter"), delivery_unit: config&.dig("delivery", "unit")) lifecycle_hooks.call(:before_start, application_context(runtime: runtime)) processed = process_consumer(runtime) lifecycle_hooks.call(:after_start, application_context(runtime: runtime, processed: processed)) operational_logger.info("application_completed", mammoth_name: config&.dig("mammoth", "name"), processed:) processed rescue StandardError => e operational_logger.error("application_failed", mammoth_name: config&.dig("mammoth", "name"), error_class: e.class.name) raise ensure lifecycle_hooks.call(:before_shutdown, application_context(runtime: runtime, processed: processed)) runtime.shutdown if runtime.respond_to?(:shutdown) lifecycle_hooks.call(:after_shutdown, application_context(runtime: runtime, processed: processed)) operational_logger.info("application_stopped", mammoth_name: config&.dig("mammoth", "name"), processed:) end |