Class: Dynflow::Config

Inherits:
Object
  • Object
show all
Includes:
Algebrick::TypeCheck
Defined in:
lib/dynflow/config.rb

Defined Under Namespace

Classes: ForWorld, QueuesConfig

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config_attr(name, *types, &default) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dynflow/config.rb', line 9

def self.config_attr(name, *types, &default)
  self.send(:define_method, "validate_#{name}!") do |value|
    Type! value, *types unless types.empty?
  end
  self.send(:define_method, name) do
    var_name = "@#{name}"
    if instance_variable_defined?(var_name)
      return instance_variable_get(var_name)
    else
      return default
    end
  end
  self.send(:attr_writer, name)
end

Instance Method Details

#queuesObject



78
79
80
# File 'lib/dynflow/config.rb', line 78

def queues
  @queues ||= QueuesConfig.new
end

#validate(config_for_world) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/dynflow/config.rb', line 199

def validate(config_for_world)
  if defined? ::ActiveRecord::Base
    begin
      ar_pool_size = ::ActiveRecord::Base.connection_pool.instance_variable_get(:@size)
      if (config_for_world.pool_size / 2.0) > ar_pool_size
        config_for_world.world.logger.warn 'Consider increasing ActiveRecord::Base.connection_pool size, ' +
                                           "it's #{ar_pool_size} but there is #{config_for_world.pool_size} " +
                                           'threads in Dynflow pool.'
      end
    rescue ActiveRecord::ConnectionNotEstablished
      # If in tests or in an environment where ActiveRecord doesn't have a
      # real DB connection, we want to skip AR configuration altogether
    end
  end
end

#validate_executor!(value) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/dynflow/config.rb', line 106

def validate_executor!(value)
  accepted_executors = [Executors::Parallel::Core]
  accepted_executors << Executors::Sidekiq::Core if defined? Executors::Sidekiq::Core
  if value && !accepted_executors.include?(value)
    raise ArgumentError, "Executor #{value} is expected to be one of #{accepted_executors.inspect}"
  end
end