module Pidly::Callbacks
Pidly
before/after callbacks
Public Class Methods
Extend and include callback methods
@param [Class] receiver The calling class
# File lib/pidly/callbacks.rb, line 133 def self.included(receiver) receiver.extend self end
Public Instance Methods
After stop
Right after the daemon is instructed to stop the following callback will be invoked and executed.
@param [Symbol] callback Method name @yield [] Code to be executed upon callback invocation
@example
after_start :method_name # OR after_start { puts "#{@pid} was just killed!" }
# File lib/pidly/callbacks.rb, line 75 def after_stop(callback=nil, &block) add_callback(:after_stop, (callback || block)) end
Before start
Right before the daemon is instructed to start the following callback will be invoked and executed.
@param [Symbol] callback Method name @yield [] Code to be executed upon callback invocation
@example
before_start :method_name # OR before_start { puts "#{@pid} is about to start!" }
# File lib/pidly/callbacks.rb, line 21 def before_start(callback=nil, &block) add_callback(:before_start, (callback || block)) end
Error
If the daemon encounters an error or an exception is raised the following callback will be invoked and executed.
@param [Symbol] callback Method name @yield [] Code to be executed upon callback invocation
@example
error :send_error_email # OR error { puts "ZOMG! #{@name} failed!" }
# File lib/pidly/callbacks.rb, line 93 def error(callback=nil, &block) add_callback(:error, (callback || block)) end
Kill
Right before the kill instruction is sent the following callback will be invoked and executed.
@param [Symbol] callback Method name @yield [] Code to be executed upon callback invocation
@example
kill :sent_kill_9_to_process # OR kill { puts "Forcefully killed process" }
# File lib/pidly/callbacks.rb, line 111 def kill(callback=nil, &block) add_callback(:kill, (callback || block)) end
Start
When the daemon is instructed to start the following callback will be invoked and executed.
@param [Symbol] callback Method name @yield [] Code to be executed upon callback invocation
@example
start :method_name # OR start { puts "Daemon Started!" }
# File lib/pidly/callbacks.rb, line 39 def start(callback=nil, &block) add_callback(:start, (callback || block)) end
Stop
When the daemon is instructed to stop the following callback will be invoked and executed.
@param [Symbol] callback Method name @yield [] Code to be executed upon callback invocation
@example
stop :method_name # OR stop { puts "Attempting to stop #{@name} with pid #{@pid}!" }
# File lib/pidly/callbacks.rb, line 57 def stop(callback=nil, &block) add_callback(:stop, (callback || block)) end
Private Instance Methods
Add callback
@param [Symbol] callback Callback method name @param [Symbol, nil] invoke Method to call @yield [] Code to be executed upon callback invocation
# File lib/pidly/callbacks.rb, line 122 def add_callback(callback, invoke) Control.instance_eval do class_variable_set(:"@@#{callback}", invoke) end end