Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move #kill_master out from outer scope and into an instance_eval

  • Loading branch information...
commit e196028c44f1d2ac624be3d38086923c7c32b1c2 1 parent 62272eb
guns authored
Showing with 16 additions and 19 deletions.
  1. +16 −19 lib/delayed/daemon_tasks.rb
35 lib/delayed/daemon_tasks.rb
View
@@ -20,20 +20,6 @@
#
# * The master polls tmp/restart.txt and restarts children on timestamp update
-### Helpers
-
-def kill_master(signal)
- pid_file = "#{Dir.pwd}/tmp/pids/delayed_worker.master.pid"
- abort 'No pid file found!' unless File.exists? pid_file
- pid = File.read(pid_file).to_i
- puts "Sending #{signal} to #{pid}"
- Process.kill signal, pid
-rescue Errno::ESRCH => e
- abort e.to_s
-end
-
-### Tasks
-
namespace :jobs do
namespace :daemon do
desc 'Spawn a daemon which forks WORKERS=n instances of Delayed::Worker'
@@ -174,10 +160,21 @@ def kill_master(signal)
Process.detach master
end
- desc 'Restart an existing delayed_worker daemon'
- task(:restart) { kill_master :SIGHUP }
-
- desc 'Stop an existing delayed_worker daemon'
- task(:stop) { kill_master :SIGTERM }
+ [%w[restart SIGHUP], %w[stop SIGTERM]].each do |name, signal|
+ instance_eval do
+ desc "#{name.capitalize} an existing delayed_worker daemon"
+ task name do
+ begin
+ pid_file = "#{Dir.pwd}/tmp/pids/delayed_worker.master.pid"
+ abort 'No pid file found!' unless File.exists? pid_file
+ pid = File.read(pid_file).to_i
+ puts "Sending #{signal} to #{pid}"
+ Process.kill signal, pid
+ rescue Errno::ESRCH => e
+ abort e.to_s
+ end
+ end
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.