lib/legion/service.rb in legionio-0.1.1 vs lib/legion/service.rb in legionio-0.2.0
- old
+ new
@@ -1,63 +1,80 @@
# frozen_string_literal: true
module Legion
- # Used for creating the actual legion service
class Service
- def initialize(_options = {})
- setup_logging
+ def modules
+ [Legion::Crypt, Legion::Transport, Legion::Cache, Legion::Data, Legion::Supervision].freeze
+ end
+
+ def initialize(transport: true, cache: true, data: true, supervision: true, extensions: true, crypt: true, log_level: 'info') # rubocop:disable Metrics/ParameterLists
+ setup_logging(log_level)
Legion::Logging.debug('Starting Legion::Service')
setup_settings
- setup_transport
- setup_sequel
- setup_supervision
- sleep(0.1)
- load_extensions
+ Legion::Logging.info "node name: #{Legion::Settings[:client][:name]}"
+
+ require 'legion/crypt' if crypt
+ Legion::Crypt.start if crypt
+ setup_transport if transport
+ setup_cache if cache
+ setup_data if data
+ setup_supervision if supervision
+ require 'legion/runner'
+
+ load_extensions if extensions
+ Legion::Crypt.setup_safe if crypt
+
+ Legion::Settings[:client][:ready] = true
end
- def setup_sequel
- require 'legion/data/connection'
- Legion::Data::Connection.new
- Legion::Data::Connection.new
- Legion::Data::Connection.new
- @connected = true
+ def setup_cache
+ require 'legion/cache'
+ Legion::Cache.setup
end
+ def setup_data
+ require 'legion/data'
+ Legion::Settings.merge_settings(:data, Legion::Data::Settings.default)
+ Legion::Data.setup
+ end
+
def setup_settings
require 'legion/settings'
Legion::Logging.debug('Loading Legion::Settings')
- @settings = Legion::Settings.load(config_dir: './settings')
+ Legion::Settings.load(config_dir: './settings')
Legion::Logging.info('Legion::Settings Loaded')
end
- def setup_logging
+ def setup_logging(_log_level = 'info')
require 'legion/logging'
- Legion::Logging.setup(level: 'info')
+ Legion::Logging.setup(level: 'info', trace: true)
end
def setup_transport
require 'legion/transport'
- require 'legion/transport/connection'
- Legion::Transport::Connection.new
+ Legion::Settings.merge_settings(:transport, Legion::Transport::Settings.default)
+ Legion::Transport::Connection.setup
end
def setup_supervision
- require 'celluloid/current'
- Celluloid.logger = Legion::Logging
require_relative('supervison')
- @supervision = Legion::Supervision.new
+ @supervision = Legion::Supervision.setup
end
def shutdown
Legion::Logging.info('Legion::Service.shutdown was called')
@shutdown = true
- @supervision.stop_supervision
- Celluloid.shutdown
+ Legion::Extensions.shutdown
+
+ sleep(0.2)
+ Legion::Data.shutdown
+ Legion::Cache.shutdown
+ Legion::Transport::Connection.shutdown
+ Legion::Crypt.shutdown
end
def load_extensions
- require 'legion/runners/runner'
- require 'legion/extension/loader'
- Legion::Extension::Loader.new(@supervision).load_extensions
+ require 'legion/runner'
+ Legion::Extensions.hook_extensions
end
end
end