Sha256: addaa811902c8c618a06e30c74eea1e4a12af93056dc1cd85ba797ee960e4f84

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require "rubygems"
require "bundler/setup"
require 'time'
require 'active_record'
require 'eventmachine'
require 'sqlite3'
require 'rflow/configuration'
require 'rflow/master'
require 'rflow/message'
require 'rflow/components'
require 'rflow/connections'
require 'rflow/logger'

class RFlow
  include Log4r

  class << self
    attr_accessor :logger
    attr_reader :configuration, :master

    RFlow.logger = RFlow::Logger.new({})
  end

  def self.run!(config_database_path = nil, daemonize = false)
    @config_database_path = config_database_path
    @daemonize = daemonize

    establish_configuration
    chdir_application_directory
    setup_logger
    start_master_node
  rescue SystemExit => e
    # Do nothing, just prevent a normal exit from causing an unsightly
    # error in the logs
  end

  private
  def self.establish_configuration
    @configuration = Configuration.new(@config_database_path)
    unless configuration['rflow.application_directory_path']
      raise ArgumentError, "Empty configuration database!  Use a view/controller (such as the RubyDSL) to create a configuration"
    end
  end

  def self.chdir_application_directory
    # First change to the config db directory, which might hold
    # relative paths for the other files/directories
    Dir.chdir(File.dirname(@config_database_path)) if @config_database_path
    Dir.chdir configuration['rflow.application_directory_path']
  end

  def self.setup_logger
    include_stdout = !@daemonize
    logger.reconfigure(configuration, include_stdout)
  end

  def self.start_master_node
    RFlow.logger.info "#{configuration['rflow.application_name']} starting"
    @master = Master.new(configuration)
    master.daemonize! if @daemonize
    master.run! # blocks until EventMachine stops
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rflow-1.0.1 lib/rflow.rb