Module: RCS::Component
- Defined in:
- lib/rcs-common/component.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #component ⇒ Object
- #component_name ⇒ Object
- #component_version ⇒ Object
- #database ⇒ Object
- #establish_database_connection(wait_until_connected: false) ⇒ Object
- #full_component_version ⇒ Object
- #run_with_rescue ⇒ Object
- #show_startup_message ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rcs-common/component.rb', line 5 def self.included(base) base.__send__(:include, RCS::Tracer) base.__send__(:extend, RCS::Tracer) base.__send__(:extend, ClassMethods) base.__send__(:define_singleton_method, :component) do |value, name: nil| @_component = value.to_sym @_component_name = name || "RCS #{value.to_s.capitalize}" end end |
Instance Method Details
#component ⇒ Object
17 18 19 |
# File 'lib/rcs-common/component.rb', line 17 def component self.class.instance_variable_get('@_component') end |
#component_name ⇒ Object
21 22 23 |
# File 'lib/rcs-common/component.rb', line 21 def component_name self.class.instance_variable_get('@_component_name') end |
#component_version ⇒ Object
29 30 31 |
# File 'lib/rcs-common/component.rb', line 29 def component_version $version || full_component_version.split('-').first end |
#database ⇒ Object
38 39 40 41 42 43 |
# File 'lib/rcs-common/component.rb', line 38 def database @_database ||= begin db_class = RCS.const_get('Collector::DB') rescue RCS.const_get('DB::DB') db_class.instance end end |
#establish_database_connection(wait_until_connected: false) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rcs-common/component.rb', line 45 def establish_database_connection(wait_until_connected: false) loop do connected = database.respond_to?(:connect!) ? database.connect!(component) : database.connect if connected trace :info, "Database connection succeeded" break end if wait_until_connected trace :warn, "Database connection failed, retry..." sleep 1 else trace :error, "Database connection failed" break end end end |
#full_component_version ⇒ Object
25 26 27 |
# File 'lib/rcs-common/component.rb', line 25 def full_component_version File.read(Dir.pwd + '/config/VERSION').strip end |
#run_with_rescue ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rcs-common/component.rb', line 64 def run_with_rescue $version = component_version trace_setup yield return 0 rescue Interrupt # call the kill handler if defined kill if self.respond_to? :kill trace :info, "User asked to exit. Bye bye!" exit(0) rescue Exception => e trace :fatal, "FAILURE: " << e. trace :fatal, "EXCEPTION: [#{e.class}] " << e.backtrace.join("\n") exit(1) end |
#show_startup_message ⇒ Object
33 34 35 36 |
# File 'lib/rcs-common/component.rb', line 33 def build = File.read(Dir.pwd + '/config/VERSION_BUILD') trace :fatal, "Starting the #{component_name} #{full_component_version} (#{build})..." end |