Module: Pidly::Callbacks

Included in:
Control
Defined in:
lib/pidly/callbacks.rb

Overview

Pidly before/after callbacks

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object

Extend and include callback methods

Parameters:

  • receiver (Class)

    The calling class



133
134
135
# File 'lib/pidly/callbacks.rb', line 133

def self.included(receiver)
  receiver.extend self
end

Instance Method Details

#after_stop(callback = nil) { ... } ⇒ Object

After stop

Right after the daemon is instructed to stop the following callback will be invoked and executed.

Examples:

after_start :method_name
# OR
after_start { puts "#{@pid} was just killed!" }

Parameters:

  • callback (Symbol) (defaults to: nil)

    Method name

Yields:

  • Code to be executed upon callback invocation



75
76
77
# File 'lib/pidly/callbacks.rb', line 75

def after_stop(callback=nil, &block)
  add_callback(:after_stop, (callback || block))
end

#before_start(callback = nil) { ... } ⇒ Object

Before start

Right before the daemon is instructed to start the following callback will be invoked and executed.

Examples:

before_start :method_name
# OR
before_start { puts "#{@pid} is about to start!" }

Parameters:

  • callback (Symbol) (defaults to: nil)

    Method name

Yields:

  • Code to be executed upon callback invocation



21
22
23
# File 'lib/pidly/callbacks.rb', line 21

def before_start(callback=nil, &block)
  add_callback(:before_start, (callback || block))
end

#error(callback = nil) { ... } ⇒ Object

Error

If the daemon encounters an error or an exception is raised the following callback will be invoked and executed.

Examples:

error :send_error_email
# OR
error { puts "ZOMG! #{@name} failed!" }

Parameters:

  • callback (Symbol) (defaults to: nil)

    Method name

Yields:

  • Code to be executed upon callback invocation



93
94
95
# File 'lib/pidly/callbacks.rb', line 93

def error(callback=nil, &block)
  add_callback(:error, (callback || block))
end

#kill(callback = nil) { ... } ⇒ Object

Kill

Right before the kill instruction is sent the following callback will be invoked and executed.

Examples:

kill :sent_kill_9_to_process
# OR
kill { puts "Forcefully killed process" }

Parameters:

  • callback (Symbol) (defaults to: nil)

    Method name

Yields:

  • Code to be executed upon callback invocation



111
112
113
# File 'lib/pidly/callbacks.rb', line 111

def kill(callback=nil, &block)
  add_callback(:kill, (callback || block))
end

#start(callback = nil) { ... } ⇒ Object

Start

When the daemon is instructed to start the following callback will be invoked and executed.

Examples:

start :method_name
# OR
start { puts "Daemon Started!" }

Parameters:

  • callback (Symbol) (defaults to: nil)

    Method name

Yields:

  • Code to be executed upon callback invocation



39
40
41
# File 'lib/pidly/callbacks.rb', line 39

def start(callback=nil, &block)
  add_callback(:start, (callback || block))
end

#stop(callback = nil) { ... } ⇒ Object

Stop

When the daemon is instructed to stop the following callback will be invoked and executed.

Examples:

stop :method_name
# OR
stop { puts "Attempting to stop #{@name} with pid #{@pid}!" }

Parameters:

  • callback (Symbol) (defaults to: nil)

    Method name

Yields:

  • Code to be executed upon callback invocation



57
58
59
# File 'lib/pidly/callbacks.rb', line 57

def stop(callback=nil, &block)
  add_callback(:stop, (callback || block))
end