Class: RFlow::Shard

Inherits:
Object
  • Object
show all
Defined in:
lib/rflow/shard.rb

Overview

An object implementation shared between two processes. The parent process will instantiate, configure, and run! a shard, at which point the parent will have access to the shard object and be able to monitor the underlying processes. The child implementation, running in a separate process, will not return from spawn!, but start an EventMachine reactor.

Defined Under Namespace

Classes: Worker

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Shard

Returns a new instance of Shard.



84
85
86
87
88
89
90
# File 'lib/rflow/shard.rb', line 84

def initialize(config)
  @config = config
  @uuid = config.uuid
  @name = config.name
  @count = config.count
  @workers = count.times.map {|i| Worker.new(self, i+1) }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



82
83
84
# File 'lib/rflow/shard.rb', line 82

def config
  @config
end

#countObject (readonly)

Returns the value of attribute count.



82
83
84
# File 'lib/rflow/shard.rb', line 82

def count
  @count
end

#nameObject (readonly)

Returns the value of attribute name.



82
83
84
# File 'lib/rflow/shard.rb', line 82

def name
  @name
end

#workersObject (readonly)

Returns the value of attribute workers.



82
83
84
# File 'lib/rflow/shard.rb', line 82

def workers
  @workers
end

Instance Method Details

#run!Object



92
93
94
95
96
97
98
# File 'lib/rflow/shard.rb', line 92

def run!
  RFlow.logger.debug "Running shard #{name} with #{count} workers"
  workers.each(&:spawn!)

  RFlow.logger.debug "#{count} workers started for #{name}: #{workers.map { |w| "#{w.name} (#{w.pid})" }.join(', ')}"
  workers
end