class Archfiend::Application
Constants
- POSSIBLE_LOGGER_LEVELS
Public Instance Methods
run()
click to toggle source
The main application entry point, it starts up all the subthreads, all the subprocesses, registers the exit handler and then it blocks the execution.
# File lib/archfiend/application.rb, line 9 def run setup logger.info 'Starting up' ThreadLoop.start_all(self) SubprocessLoop.start_all(self) run_clockwork # Setup after subprocesses are created, so the handler is not copied to them setup_cleanup loop { sleep 1 } end
setup()
click to toggle source
# File lib/archfiend/application.rb, line 23 def setup return if @already_setup setup_timezone setup_settings setup_logger setup_activerecord setup_debug run_initializers require_app_classes @already_setup = true end
Private Instance Methods
require_app_classes()
click to toggle source
# File lib/archfiend/application.rb, line 46 def require_app_classes rb_pattern = utils.root.join('app', '**', '*.rb') Dir[rb_pattern].each { |file_name| require file_name } end
run_clockwork()
click to toggle source
Starts a new thread that runs tasks defined in the Clockwork module.
# File lib/archfiend/application.rb, line 69 def run_clockwork return unless self.class.const_defined?('Clockwork') th = Thread.new do ::Clockwork.run end th[:name] = 'Clockwork' end
run_initializers()
click to toggle source
# File lib/archfiend/application.rb, line 40 def run_initializers Dir[utils.root.join('config', 'initializers', '**', '*.rb')].sort.each do |ruby_file| load ruby_file end end
setup_activerecord()
click to toggle source
# File lib/archfiend/application.rb, line 51 def setup_activerecord # TODO: ensure connection timezone is correct yaml_text = ERB.new(IO.read(utils.root.join('config', 'database.yml'))).result ::ActiveRecord::Base.configurations = YAML.load(yaml_text) # rubocop:disable Security/YAMLLoad ::ActiveRecord::Base.establish_connection(env.to_sym) ::ActiveRecord::Base.logger = utils.logger if %w[development test].include?(env) end
setup_cleanup()
click to toggle source
Registers actions to be performed when the ruby vm exits
# File lib/archfiend/application.rb, line 88 def setup_cleanup at_exit do utils.logger.info 'Exiting' SubprocessLoop.kill_all end end
setup_debug()
click to toggle source
# File lib/archfiend/application.rb, line 95 def setup_debug return unless Settings.debug&.rbtrace require 'rbtrace' rescue LoadError => e puts 'Settings.debug.rbtrace is true but cannot load the "rbtrace" gem, make sure it is present in Gemfile' puts "(#{e})" exit 1 end
setup_logger()
click to toggle source
# File lib/archfiend/application.rb, line 79 def setup_logger logger_level = Settings.logger&.level fail "Please set logger.level setting (#{POSSIBLE_LOGGER_LEVELS.inspect})" unless POSSIBLE_LOGGER_LEVELS.include?(logger_level) utils.logger.level = logger_level utils.logger.progname = name end
setup_settings()
click to toggle source
# File lib/archfiend/application.rb, line 64 def setup_settings ::Config.load_and_set_settings(::Config.setting_files(utils.root.join('config'), env)) end
setup_timezone()
click to toggle source
# File lib/archfiend/application.rb, line 60 def setup_timezone Time.zone_default = ActiveSupport::TimeZone['UTC'] end