Method: Wildcloud::Keeper::Runtime#initialize

Defined in:
lib/wildcloud/keeper/runtime.rb

#initializeRuntime

Returns a new instance of Runtime.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wildcloud/keeper/runtime.rb', line 31

def initialize
  @repository = {}

  Keeper.logger.info('Runtime') { 'Starting transport' }
  @transport = Transport::Amqp.new

  Keeper.logger.info('Runtime') { 'Starting thread-pool' }
  @queue = Queue.new
  @thread_pool = []

  Keeper.configuration['workers'].times do |i|
    Keeper.logger.debug('Runtime', "Starting thread ##{i}")
    Thread.new(i) do |id|
      Thread.current.abort_on_exception = false
      loop do
        Keeper.logger.debug('Runtime') { "Thread ##{id} waiting for task" }
        begin
          @queue.pop.call
        rescue Exception => exception
          Keeper.logger.fatal('Runtime') { "Exception in thread #{id}: #{exception.message}" }
          Keeper.logger.debug('Runtime') { exception }
          Keeper.logger.debug('Runtime') { exception.backtrace }
        else
          Keeper.logger.debug('Runtime') { "Thread ##{id} handled task successfully" }
        end
      end
    end
  end

  handler = self.method(:handle)
  @transport.start(&handler)
  @transport.send({:type => :sshkey, :node => Keeper.configuration['node']['name'], :key => File.read(File.expand_path('~/.ssh/id_rsa.pub')).strip}, :master)
end