Class: Preforker::Worker::WorkerAPI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, master) ⇒ WorkerAPI

Returns a new instance of WorkerAPI.



9
10
11
12
13
14
15
# File 'lib/preforker/worker.rb', line 9

def initialize(worker, master)
  @master = master
  @logger = master.logger
  @worker = worker
  @alive = @worker.tmp
  @last_file_bit = 0
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



7
8
9
# File 'lib/preforker/worker.rb', line 7

def logger
  @logger
end

Instance Method Details

#killObject



26
27
28
29
30
31
# File 'lib/preforker/worker.rb', line 26

def kill
  if @alive
    @worker.log "Exiting gracefully"
    @alive = false
  end
end

#wants_me_alive?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
# File 'lib/preforker/worker.rb', line 17

def wants_me_alive?
  if @alive
    #we are alive, let's be thankful and tell master we are alive and happy
    @last_file_bit = 0 == @last_file_bit ? 1 : 0
    @alive.chmod(@last_file_bit)
  end
  @alive
end