Class: Hive::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/hive/policy.rb

Constant Summary collapse

DEFAULTS =
{
  pool_min_workers:       1,
  pool_max_workers:       10,
  worker_idle_max_sleep:  64.0,
  worker_idle_min_sleep:  0.125,
  worker_idle_spin_down:  900,
  worker_none_spin_up:    86400,
  worker_max_jobs:        100,    # a worker should automatically exit after this many jobs
  worker_max_lifetime:    1000,   # a worker should automatically exit after this time
  worker_late:            10,     # a worker is overdue after this time with no heartbeat
  worker_hung:            100,    # a worker will be killed after this time
  storage:                :mock,
  observers:              []
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Policy

Returns a new instance of Policy.



20
21
22
23
# File 'lib/hive/policy.rb', line 20

def initialize( options = {} )
  options  = Hash[ options.map { |k,v| [ k.to_sym, v ] } ] # poor man's symbolize keys
  @options = DEFAULTS.merge( options )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *arguments) ⇒ Object



29
30
31
# File 'lib/hive/policy.rb', line 29

def method_missing( symbol, *arguments )
  @options[symbol.to_sym]
end

Class Method Details

.resolve(options_or_policy = {}) ⇒ Object



53
54
55
56
# File 'lib/hive/policy.rb', line 53

def resolve( options_or_policy = {} )
  # if it is a policy, just dup it
  options_or_policy.kind_of?(Hive::Policy) ? options_or_policy.dup : new(options_or_policy.dup)
end

Instance Method Details

#after_forkObject



46
47
48
# File 'lib/hive/policy.rb', line 46

def after_fork
  (after_forks || []).each { |f| f.call }
end

#before_forkObject



42
43
44
# File 'lib/hive/policy.rb', line 42

def before_fork
  (before_forks || []).each { |f| f.call }
end

#dupObject



38
39
40
# File 'lib/hive/policy.rb', line 38

def dup
  self.class.new( @options.dup )
end

#merge(options = {}) ⇒ Object



33
34
35
36
# File 'lib/hive/policy.rb', line 33

def merge( options = {} )
  @options.merge!( options )
  self
end

#storageObject



25
26
27
# File 'lib/hive/policy.rb', line 25

def storage
  Hive::Utilities::StorageBase.resolve @options[:storage]
end