Class: EventMachine::ProcessWatch

Inherits:
Connection show all
Defined in:
lib/em/process_watch.rb

Overview

This is subclassed from EventMachine::Connection for use with the process monitoring API. Read the documentation on the instance methods of this class, and for a full explanation see EventMachine.watch_process.

Constant Summary

Cfork =
'fork'.freeze
Cexit =
'exit'.freeze

Instance Attribute Summary

Attributes inherited from Connection

#signature

Instance Method Summary collapse

Methods inherited from Connection

#associate_callback_target, #close_connection, #close_connection_after_writing, #comm_inactivity_timeout, #comm_inactivity_timeout=, #connection_completed, #detach, #error?, #get_cipher_bits, #get_cipher_name, #get_cipher_protocol, #get_idle_time, #get_outbound_data_size, #get_peer_cert, #get_peername, #get_pid, #get_proxied_bytes, #get_sni_hostname, #get_sock_opt, #get_sockname, #get_status, #initialize, new, #notify_readable=, #notify_readable?, #notify_writable=, #notify_writable?, #pause, #paused?, #pending_connect_timeout, #pending_connect_timeout=, #post_init, #proxy_completed, #proxy_incoming_to, #proxy_target_unbound, #reconnect, #resume, #send_data, #send_datagram, #send_file_data, #set_sock_opt, #ssl_handshake_completed, #ssl_verify_peer, #start_tls, #stop_proxying, #stream_file_data, #unbind

Constructor Details

This class inherits a constructor from EventMachine::Connection

Instance Method Details

#pidObject

Returns the pid that EventMachine::watch_process was originally called with.



22
23
24
# File 'lib/em/process_watch.rb', line 22

def pid
  @pid
end

#process_exitedObject

Should be redefined with the user's custom callback that will be fired when the process exits.

stop_watching is called automatically after this callback



35
36
# File 'lib/em/process_watch.rb', line 35

def process_exited
end

#process_forkedObject

Should be redefined with the user's custom callback that will be fired when the prcess is forked.

There is currently not an easy way to get the pid of the forked child.



29
30
# File 'lib/em/process_watch.rb', line 29

def process_forked
end

#receive_data(data) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/em/process_watch.rb', line 12

def receive_data(data)
  case data
  when Cfork
    process_forked
  when Cexit
    process_exited
  end
end

#stop_watchingObject

Discontinue monitoring of the process. This will be called automatically when a process dies. User code may call it as well.



40
41
42
# File 'lib/em/process_watch.rb', line 40

def stop_watching
  EventMachine::unwatch_pid(@signature)
end