class SandthornSequelProjection::Runner

Constants

DEFAULT_INTERVAL

Attributes

interval[R]
manifest[R]

Public Class Methods

new(manifest, interval = DEFAULT_INTERVAL) click to toggle source
# File lib/sandthorn_sequel_projection/runner.rb, line 8
def initialize(manifest, interval = DEFAULT_INTERVAL)
  @manifest = manifest
  @interval = interval
end

Public Instance Methods

run(infinite = true) click to toggle source
# File lib/sandthorn_sequel_projection/runner.rb, line 13
def run(infinite = true)
  @projections = manifest.projections.map do |projection_class|
    projection_class.new(db_connection)
  end
  migrate!
  if infinite
    start_loop
  else
    loop_once
  end
end

Private Instance Methods

db_connection() click to toggle source
# File lib/sandthorn_sequel_projection/runner.rb, line 40
def db_connection
  SandthornSequelProjection.configuration.db_connection
end
loop_once() click to toggle source
# File lib/sandthorn_sequel_projection/runner.rb, line 33
def loop_once
  @projections.each do |projection|
    projection.update!
  end
  sleep(interval)
end
migrate!() click to toggle source
# File lib/sandthorn_sequel_projection/runner.rb, line 44
def migrate!
  @projections.each(&:migrate!)
end
start_loop() click to toggle source
# File lib/sandthorn_sequel_projection/runner.rb, line 27
def start_loop
  while true
    loop_once
  end
end