Class: Proxy::Dynflow::Core
- Inherits:
-
Object
- Object
- Proxy::Dynflow::Core
- Defined in:
- lib/smart_proxy_dynflow/core.rb
Class Attribute Summary collapse
-
.instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Attribute Summary collapse
-
#accepted_cert_serial ⇒ Object
Returns the value of attribute accepted_cert_serial.
-
#world ⇒ Object
Returns the value of attribute world.
Class Method Summary collapse
- .after_initialize(&block) ⇒ Object
- .ensure_initialized ⇒ Object
- .register_silencer_matchers(matchers) ⇒ Object
- .silencer_matchers ⇒ Object
- .web_console ⇒ Object
- .world ⇒ Object
Instance Method Summary collapse
- #create_world(&block) ⇒ Object
- #default_world_config ⇒ Object
- #execution_plan_cleaner ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #logger_adapter ⇒ Object
- #persistence_adapter ⇒ Object
- #persistence_conn_string ⇒ Object
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/smart_proxy_dynflow/core.rb', line 7 def initialize @world = create_world cert_file = Proxy::SETTINGS.foreman_ssl_cert || Proxy::SETTINGS.ssl_certificate if cert_file client_cert = File.read(cert_file) # we trust only requests using the same certificate as we are # (in other words the local proxy only) @accepted_cert_serial = OpenSSL::X509::Certificate.new(client_cert).serial end end |
Class Attribute Details
.instance ⇒ Object (readonly)
Returns the value of attribute instance.
71 72 73 |
# File 'lib/smart_proxy_dynflow/core.rb', line 71 def instance @instance end |
Instance Attribute Details
#accepted_cert_serial ⇒ Object
Returns the value of attribute accepted_cert_serial.
5 6 7 |
# File 'lib/smart_proxy_dynflow/core.rb', line 5 def accepted_cert_serial @accepted_cert_serial end |
#world ⇒ Object
Returns the value of attribute world.
5 6 7 |
# File 'lib/smart_proxy_dynflow/core.rb', line 5 def world @world end |
Class Method Details
.after_initialize(&block) ⇒ Object
113 114 115 |
# File 'lib/smart_proxy_dynflow/core.rb', line 113 def after_initialize(&block) after_initialize_blocks << block end |
.ensure_initialized ⇒ Object
73 74 75 76 77 78 |
# File 'lib/smart_proxy_dynflow/core.rb', line 73 def ensure_initialized return @instance if @instance @instance = Core.new after_initialize_blocks.each { |block| block.call(@instance) } @instance end |
.register_silencer_matchers(matchers) ⇒ Object
84 85 86 |
# File 'lib/smart_proxy_dynflow/core.rb', line 84 def register_silencer_matchers(matchers) silencer_matchers.concat matchers end |
.silencer_matchers ⇒ Object
80 81 82 |
# File 'lib/smart_proxy_dynflow/core.rb', line 80 def silencer_matchers @matchers ||= [::Dynflow::DeadLetterSilencer::Matcher.new(Ticker)] end |
.web_console ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/smart_proxy_dynflow/core.rb', line 88 def web_console require 'dynflow/web' dynflow_console = ::Dynflow::Web.setup do # we can't use the proxy's after_activation hook, as # it happens before the Daemon forks the process (including # closing opened file descriptors) # TODO: extend smart proxy to enable hooks that happen after # the forking helpers Helpers include ::Sinatra::Authorization::Helpers before do if Settings.instance.console_auth end Core.ensure_initialized set :world, Core.world end dynflow_console end |
.world ⇒ Object
109 110 111 |
# File 'lib/smart_proxy_dynflow/core.rb', line 109 def world instance.world end |
Instance Method Details
#create_world(&block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/smart_proxy_dynflow/core.rb', line 18 def create_world(&block) config = default_world_config(&block) world = ::Dynflow::World.new(config) world.middleware.use ::Actions::Middleware::KeepCurrentRequestID world end |
#default_world_config ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/smart_proxy_dynflow/core.rb', line 45 def default_world_config ::Dynflow::Config.new.tap do |config| config.auto_rescue = true config.logger_adapter = logger_adapter config.persistence_adapter = persistence_adapter config.execution_plan_cleaner = execution_plan_cleaner # TODO: There has to be a better way matchers = config.silent_dead_letter_matchers.call.concat(self.class.silencer_matchers) config.silent_dead_letter_matchers = matchers yield config if block_given? end end |
#execution_plan_cleaner ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/smart_proxy_dynflow/core.rb', line 62 def execution_plan_cleaner proc do |world| age = Settings.instance.execution_plan_cleaner_age = { :poll_interval => age, :max_age => age } ::Dynflow::Actors::ExecutionPlanCleaner.new(world, ) end end |
#logger_adapter ⇒ Object
58 59 60 |
# File 'lib/smart_proxy_dynflow/core.rb', line 58 def logger_adapter Log::ProxyAdapter.new(Proxy::LogBuffer::Decorator.instance, Log.instance.level) end |
#persistence_adapter ⇒ Object
41 42 43 |
# File 'lib/smart_proxy_dynflow/core.rb', line 41 def persistence_adapter ::Dynflow::PersistenceAdapters::Sequel.new persistence_conn_string end |
#persistence_conn_string ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smart_proxy_dynflow/core.rb', line 25 def persistence_conn_string return ENV['DYNFLOW_DB_CONN_STRING'] if ENV.key? 'DYNFLOW_DB_CONN_STRING' db_conn_string = 'sqlite:/' db_file = Settings.instance.database if db_file.nil? || db_file.empty? Log.instance.warn "Could not open DB for dynflow at '#{db_file}', " \ "will keep data in memory. Restart will drop all dynflow data." else FileUtils.mkdir_p(File.dirname(db_file)) db_conn_string += "/#{db_file}" end db_conn_string end |