lib/foreman_tasks/dynflow/configuration.rb in foreman-tasks-0.6.15 vs lib/foreman_tasks/dynflow/configuration.rb in foreman-tasks-0.7.0
- old
+ new
@@ -16,14 +16,10 @@
# set true if the executor runs externally (by default true in procution, othewise false)
attr_accessor :remote
alias_method :remote?, :remote
- # if remote set to true, use this path for socket communication
- # between this process and the external executor
- attr_accessor :remote_socket_path
-
# what transaction adapater should be used, by default, it uses the ActiveRecord
# based adapter, expecting ActiveRecord is used as ORM in the application
attr_accessor :transaction_adapter
attr_accessor :eager_load_paths
@@ -42,11 +38,10 @@
self.action_logger = Rails.logger
self.dynflow_logger = Rails.logger
self.pool_size = 5
self.db_pool_size = pool_size + 5
self.remote = Rails.env.production?
- self.remote_socket_path = File.join(Rails.root, "tmp", "sockets", "dynflow_socket")
self.transaction_adapter = ::Dynflow::TransactionAdapters::ActiveRecord.new
self.eager_load_paths = []
self.lazy_initialization = !Rails.env.production?
self.rake_tasks_with_executor = %w[db:migrate db:seed]
@@ -56,11 +51,11 @@
def on_init(&block)
@on_init << block
end
def initialize_world(world_class = ::Dynflow::World)
- world_class.new(world_options).tap do |world|
+ world_class.new(world_config).tap do |world|
@on_init.each { |init| init.call(world) }
end
end
# No matter what config.remote says, when the process is marked as executor,
@@ -96,16 +91,23 @@
end
protected
# generates the options hash consumable by the Dynflow's world
- def world_options
- { logger_adapter: ::Dynflow::LoggerAdapters::Delegator.new(action_logger, dynflow_logger),
- pool_size: 5,
- persistence_adapter: initialize_persistence,
- transaction_adapter: transaction_adapter,
- executor: -> world { initialize_executor world } }
+ def world_config
+ ::Dynflow::Config.new.tap do |config|
+ config.auto_rescue = true
+ config.logger_adapter = ::Dynflow::LoggerAdapters::Delegator.new(action_logger, dynflow_logger)
+ config.pool_size = 5
+ config.persistence_adapter = initialize_persistence
+ config.transaction_adapter = transaction_adapter
+ config.executor = ->(world, _) { initialize_executor(world) }
+ config.connector = ->(world, _) { initialize_connector(world) }
+
+ # we can't do any operation until the ForemanTasks.dynflow.world is set
+ config.auto_execute = false
+ end
end
def default_sequel_adapter_options
db_config = ActiveRecord::Base.configurations[Rails.env].dup
db_config['adapter'] = 'postgres' if db_config['adapter'] == 'postgresql'
@@ -123,13 +125,17 @@
return db_config
end
def initialize_executor(world)
if self.remote?
- ::Dynflow::Executors::RemoteViaSocket.new(world, self.remote_socket_path)
+ false
else
::Dynflow::Executors::Parallel.new(world, self.pool_size)
end
+ end
+
+ def initialize_connector(world)
+ ::Dynflow::Connectors::Database.new(world)
end
# Sequel adapter based on Rails app database.yml configuration
def initialize_persistence
ForemanTasks::Dynflow::Persistence.new(default_sequel_adapter_options)