Class: Guard::Shoryuken
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Shoryuken
- Defined in:
- lib/guard/shoryuken.rb
Constant Summary collapse
- DEFAULT_SIGNAL =
:TERM
- DEFAULT_CONCURRENCY =
25
- BASE_CMD =
'bundle exec shoryuken'
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Shoryuken
constructor
Allowable options are: - :concurrency INT e.g.
-
#reload ⇒ Object
Called on Ctrl-Z signal.
- #restart ⇒ Object
-
#run_all ⇒ Object
Called on Ctrl-/ signal.
-
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Shoryuken
Allowable options are:
- :concurrency INT e.g. 10, processor threads to use
- :queue QUEUE[,WEIGHT]... e.g. 'my_queue,5' 'my_other_queue', queues to process with optional weights
- :require [PATH|DIR] e.g. 'workers/my_worker.rb' | 'app/workers', location of the worker
- :config [PATH] e.g. 'config/my_config.yml', path to YAML config file
- :rails BOOL e.g. true, attempts to load the containing Rails project, implies :config => 'config/shoryuken.yml'
- :logfile PATH e.g. 'log/my_logfile.log', path to writable logfile
- :pidfile PATH e.g. 'my_pidfile.pid', path to pidfile
- :verbose BOOL e.g. true, print more verbose output
- :stop_signal SIGN e.g. :TERM, signal to send to stop the process
22 23 24 25 26 27 |
# File 'lib/guard/shoryuken.rb', line 22 def initialize( = {}) @options = @pid = nil @stop_signal = [:stop_signal] || DEFAULT_SIGNAL super end |
Instance Method Details
#reload ⇒ Object
Called on Ctrl-Z signal
60 61 62 63 |
# File 'lib/guard/shoryuken.rb', line 60 def reload Guard::Compat::UI.info 'Restarting shoryuken...' restart end |
#restart ⇒ Object
75 76 77 78 |
# File 'lib/guard/shoryuken.rb', line 75 def restart stop start end |
#run_all ⇒ Object
Called on Ctrl-/ signal
66 67 68 |
# File 'lib/guard/shoryuken.rb', line 66 def run_all true end |
#run_on_changes(paths) ⇒ Object
Called on file(s) modifications
71 72 73 |
# File 'lib/guard/shoryuken.rb', line 71 def run_on_changes(paths) restart end |
#start ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/guard/shoryuken.rb', line 29 def start stop Guard::Compat::UI.info 'Starting up shoryuken...' Guard::Compat::UI.info cmd # launch Shoryuken worker @pid = spawn({}, cmd) end |
#stop ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/guard/shoryuken.rb', line 38 def stop if @pid Guard::Compat::UI.info 'Stopping shoryuken...' ::Process.kill @stop_signal, @pid begin Timeout.timeout(15) do ::Process.wait @pid end rescue Timeout::Error Guard::Compat::UI.info 'Sending SIGKILL to shoryuken, as it\'s taking too long to shutdown.' ::Process.kill :KILL, @pid ::Process.wait @pid end UI.info 'Stopped process shoryuken' end rescue Errno::ESRCH Guard::Compat::UI.info 'Guard::Shoryuken lost the Shoryuken worker subprocess!' ensure @pid = nil end |