Sha256: c43b12a879e394af8a3d35607c69c22ca5de558b9c8782116a799e2f6fdb327c

Contents?: true

Size: 1.24 KB

Versions: 140

Compression:

Stored size: 1.24 KB

Contents

module EventMachine

  # 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.
  class ProcessWatch < Connection
    # @private
    Cfork = 'fork'.freeze
    # @private
    Cexit = 'exit'.freeze

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

    # Returns the pid that EventMachine::watch_process was originally called with.
    def pid
      @pid
    end

    # 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.
    def process_forked
    end

    # 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
    def process_exited
    end

    # Discontinue monitoring of the process.
    # This will be called automatically when a process dies. User code may call it as well.
    def stop_watching
      EventMachine::unwatch_pid(@signature)
    end
  end

end

Version data entries

140 entries across 137 versions & 11 rubygems

Version Path
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/eventmachine-1.2.7/lib/em/process_watch.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/process_watch.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/eventmachine-1.2.7/lib/em/process_watch.rb
eventmachine-mkroman-1.3.0.dev.1 lib/em/process_watch.rb
wj_eventmachine-1.3.2 lib/em/process_watch.rb
wj_eventmachine-1.3.1 lib/em/process_watch.rb
wj_eventmachine-1.3.0.dev.1 lib/em/process_watch.rb
sensu-em-2.7.0-java lib/em/process_watch.rb
eventmachine-1.2.7-java lib/em/process_watch.rb
eventmachine-1.2.7-x64-mingw32 lib/em/process_watch.rb
eventmachine-1.2.7-x86-mingw32 lib/em/process_watch.rb
eventmachine-1.2.7 lib/em/process_watch.rb
eventmachine-1.2.6-x64-mingw32 lib/em/process_watch.rb
eventmachine-1.2.6-x86-mingw32 lib/em/process_watch.rb
eventmachine-1.2.6-java lib/em/process_watch.rb
eventmachine-1.2.6 lib/em/process_watch.rb
eventmachine-1.2.5-x86-mingw32 lib/em/process_watch.rb
eventmachine-1.2.5-x64-mingw32 lib/em/process_watch.rb
eventmachine-1.2.5-java lib/em/process_watch.rb
eventmachine-1.2.5 lib/em/process_watch.rb