Class: Mammoth::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/application.rb

Overview

Top-level Mammoth application composition root.

Application wires Mammoth’s current v0.1.0 runtime pieces: configuration, SQLite operational memory, replication boundary, delivery worker, checkpoint store, dead letter store, and webhook sink.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, source: nil, adapter: nil, sink: nil, sleeper: Kernel.method(:sleep)) ⇒ Application

Returns a new instance of Application.

Parameters:

  • config (Mammoth::Configuration)

    loaded configuration

  • source (#each, nil) (defaults to: nil)

    injectable event source for tests and demos

  • adapter (#call, nil) (defaults to: nil)

    optional source adapter

  • sink (#deliver, nil) (defaults to: nil)

    optional destination sink

  • sleeper (#call) (defaults to: Kernel.method(:sleep))

    retry sleep strategy



17
18
19
20
21
22
# File 'lib/mammoth/application.rb', line 17

def initialize(config, source: nil, adapter: nil, sink: nil, sleeper: Kernel.method(:sleep))
  @config = config
  @sqlite_store = SQLiteStore.connect(config.dig("sqlite", "path")).bootstrap!
  @consumer = ReplicationConsumer.new(config, source: source, adapter: adapter)
  @delivery_worker = build_delivery_worker(sink: sink || WebhookSink.from_config(config), sleeper: sleeper)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/mammoth/application.rb', line 10

def config
  @config
end

#consumerObject (readonly)

Returns the value of attribute consumer.



10
11
12
# File 'lib/mammoth/application.rb', line 10

def consumer
  @consumer
end

#delivery_workerObject (readonly)

Returns the value of attribute delivery_worker.



10
11
12
# File 'lib/mammoth/application.rb', line 10

def delivery_worker
  @delivery_worker
end

#sqlite_storeObject (readonly)

Returns the value of attribute sqlite_store.



10
11
12
# File 'lib/mammoth/application.rb', line 10

def sqlite_store
  @sqlite_store
end

Instance Method Details

#startInteger

Start the application runtime and deliver consumed events.

Returns:

  • (Integer)

    number of processed events



27
28
29
30
31
32
33
34
# File 'lib/mammoth/application.rb', line 27

def start
  processed = 0
  consumer.start do |event|
    delivery_worker.deliver(event)
    processed += 1
  end
  processed
end