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 Worker 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.



113
114
115
116
117
118
119
# File 'lib/rflow/shard.rb', line 113

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

#configConfiguration::Shard (readonly)

Reference to the RFlow::Shard‘s configuration.



99
100
101
# File 'lib/rflow/shard.rb', line 99

def config
  @config
end

#countInteger (readonly)

The count of workers that should be started.

Returns:

  • (Integer)


107
108
109
# File 'lib/rflow/shard.rb', line 107

def count
  @count
end

#nameString (readonly)

The RFlow::Shard‘s name.

Returns:

  • (String)


103
104
105
# File 'lib/rflow/shard.rb', line 103

def name
  @name
end

#workersArray<Worker> (readonly)

Reference to the actual Workers.

Returns:



111
112
113
# File 'lib/rflow/shard.rb', line 111

def workers
  @workers
end

Instance Method Details

#run!void

This method returns an undefined value.

Start the shard by spawning and starting all the workers.



123
124
125
126
127
128
129
# File 'lib/rflow/shard.rb', line 123

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