lib/rflow.rb in rflow-1.0.0a1 vs lib/rflow.rb in rflow-1.0.0a2
- old
+ new
@@ -1,68 +1,60 @@
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 Error < StandardError; end
-
class << self
- attr_accessor :config_database_path
attr_accessor :logger
- attr_accessor :configuration
- attr_accessor :master
+ attr_reader :configuration, :master
end
- def self.run(config_database_path=nil, daemonize=nil)
- self.configuration = Configuration.new(config_database_path)
+ def self.run!(config_database_path = nil, daemonize = false)
+ @config_database_path = config_database_path
+ @daemonize = daemonize
- if config_database_path
- # First change to the config database directory, which might hold
- # relative paths for the other files/directories, such as the
- # application_directory_path
- Dir.chdir File.dirname(config_database_path)
- end
+ 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
- # Bail unless you have some of the basic information. TODO:
- # rethink this when things get more dynamic
+ private
+ def self.establish_configuration
+ @configuration = Configuration.new(@config_database_path)
unless configuration['rflow.application_directory_path']
- error_message = "Empty configuration database! Use a view/controller (such as the RubyDSL) to create a configuration"
- RFlow.logger.error "Empty configuration database! Use a view/controller (such as the RubyDSL) to create a configuration"
- raise ArgumentError, error_message
+ 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
- self.logger = RFlow::Logger.new(configuration, !daemonize)
- @master = Master.new(configuration)
-
- master.daemonize! if daemonize
- master.run # Runs EM and doesn't return
-
- # Should never get here
- logger.warn "going down"
- rescue SystemExit => e
- # Do nothing, just prevent a normal exit from causing an unsightly
- # error in the logs
- rescue Exception => e
- logger.fatal "Exception caught: #{e.class} - #{e.message}\n#{e.backtrace.join "\n"}"
- exit 1
+ def self.setup_logger
+ include_stdout = !@daemonize
+ self.logger = RFlow::Logger.new(configuration, include_stdout)
end
-end # class RFlow
+ def self.start_master_node
+ @master = Master.new(configuration)
+ master.daemonize! if @daemonize
+ master.run! # blocks until EventMachine stops
+ end
+end