Class: ServerEngine::Worker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, worker_id) ⇒ Worker

Returns a new instance of Worker.



24
25
26
27
28
# File 'lib/serverengine/worker.rb', line 24

def initialize(server, worker_id)
  @server = server
  @logger = @server.logger
  @worker_id = worker_id
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



31
32
33
# File 'lib/serverengine/worker.rb', line 31

def logger
  @logger
end

#serverObject (readonly)

Returns the value of attribute server.



30
31
32
# File 'lib/serverengine/worker.rb', line 30

def server
  @server
end

#worker_idObject (readonly)

Returns the value of attribute worker_id.



30
31
32
# File 'lib/serverengine/worker.rb', line 30

def worker_id
  @worker_id
end

Instance Method Details

#after_startObject



54
55
# File 'lib/serverengine/worker.rb', line 54

def after_start
end

#before_forkObject



37
38
# File 'lib/serverengine/worker.rb', line 37

def before_fork
end

#configObject



33
34
35
# File 'lib/serverengine/worker.rb', line 33

def config
  @server.config
end

#dumpObject



57
58
59
# File 'lib/serverengine/worker.rb', line 57

def dump
  Sigdump.dump unless config[:disable_sigdump]
end

#install_signal_handlersObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/serverengine/worker.rb', line 61

def install_signal_handlers
  w = self
  SignalThread.new do |st|
    st.trap(Signals::GRACEFUL_STOP) { w.stop }
    st.trap(Signals::IMMEDIATE_STOP, 'SIG_DFL')

    st.trap(Signals::GRACEFUL_RESTART) { w.stop }
    st.trap(Signals::IMMEDIATE_RESTART, 'SIG_DFL')

    st.trap(Signals::RELOAD) {
      w.logger.reopen!
      w.reload
    }
    st.trap(Signals::DETACH) { w.stop }

    st.trap(Signals::DUMP) { w.dump }
  end
end

#mainObject



80
81
82
# File 'lib/serverengine/worker.rb', line 80

def main
  run
end

#reloadObject



51
52
# File 'lib/serverengine/worker.rb', line 51

def reload
end

#runObject

Raises:

  • (NoMethodError)


40
41
42
# File 'lib/serverengine/worker.rb', line 40

def run
  raise NoMethodError, "Worker#run method is not implemented"
end

#spawn(process_manager) ⇒ Object

Raises:

  • (NoMethodError)


44
45
46
# File 'lib/serverengine/worker.rb', line 44

def spawn(process_manager)
  raise NoMethodError, "Worker#spawn(process_manager) method is required for worker_type=spawn"
end

#stopObject



48
49
# File 'lib/serverengine/worker.rb', line 48

def stop
end