Class: Neetodeploy::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/neetodeploy/autoscale/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



10
11
12
13
14
# File 'lib/neetodeploy/autoscale/worker.rb', line 10

def initialize
  @mutex = Mutex.new
  @queue = Queue.new

end

Instance Attribute Details

#mutexObject (readonly)

Returns the value of attribute mutex.



8
9
10
# File 'lib/neetodeploy/autoscale/worker.rb', line 8

def mutex
  @mutex
end

#queueObject (readonly)

Returns the value of attribute queue.



8
9
10
# File 'lib/neetodeploy/autoscale/worker.rb', line 8

def queue
  @queue
end

#threadObject (readonly)

Returns the value of attribute thread.



8
9
10
# File 'lib/neetodeploy/autoscale/worker.rb', line 8

def thread
  @thread
end

Instance Method Details

#push(msg) ⇒ Object



16
17
18
# File 'lib/neetodeploy/autoscale/worker.rb', line 16

def push(msg)
  start && queue.push(msg)
end

#startObject



20
21
22
23
24
25
26
27
# File 'lib/neetodeploy/autoscale/worker.rb', line 20

def start
  mutex.synchronize do
    return true if thread&.alive?

    @thread = Thread.new { run }
  end
  true
end