Skip to content

Commit

Permalink
Merge branch 'defunkt' into distributed
Browse files Browse the repository at this point in the history
  • Loading branch information
mpd committed Aug 22, 2011
2 parents 65780fc + f0f1694 commit 6caf6b6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
18 changes: 18 additions & 0 deletions HISTORY.md
@@ -1,3 +1,21 @@
## 1.18.2 (2011-08-19)

* Fix RAILS_ROOT deprecation warning

## 1.18.1 (2011-08-19)

* Bugfix: Use RAILS_ROOT in preload task

## 1.18.0 (2011-08-18)

* Added before_enqueue hook.
* Resque workers now preload files under app/ in Rails
* Switch to MultiJSON
* Bugfix: Finding worker pids on Solaris
* Web UI: Fix NaN days ago for worker screens
* Web UI: Add Cache-Control header to prevent proxy caching
* Web UI: Update Resque.redis_id so it can be used in a distributed ring.

## 1.17.1 (2011-05-27)

* Reverted `exit` change. Back to `exit!`.
Expand Down
11 changes: 10 additions & 1 deletion lib/resque/tasks.rb
Expand Up @@ -5,7 +5,7 @@
task :setup

desc "Start a Resque worker"
task :work => :setup do
task :work => [ :preload, :setup ] do
require 'resque'

queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',')
Expand Down Expand Up @@ -39,4 +39,13 @@

threads.each { |thread| thread.join }
end

# Preload app files if this is Rails
task :preload do
if defined? Rails
Dir["#{Rails.root}/app/**/*.rb"].each do |file|
require file
end
end
end
end
2 changes: 1 addition & 1 deletion lib/resque/version.rb
@@ -1,3 +1,3 @@
module Resque
Version = VERSION = '1.17.1'
Version = VERSION = '1.18.2'
end
30 changes: 28 additions & 2 deletions lib/resque/worker.rb
Expand Up @@ -312,7 +312,7 @@ def kill_child
def paused?
@paused
end

# Stop processing jobs after the current one has completed (if we're
# currently running one).
def pause_processing
Expand Down Expand Up @@ -483,14 +483,40 @@ def pid
@pid ||= to_s.split(":")[1].to_i
end

# Returns an array of string pids of all the other workers on this
# Returns an Array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def worker_pids
if RUBY_PLATFORM =~ /solaris/
solaris_worker_pids
else
linux_worker_pids
end
end

# Find Resque worker pids on Linux and OS X.
#
# Returns an Array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def linux_worker_pids
`ps -A -o pid,command | grep [r]esque | grep -v "resque-web"`.split("\n").map do |line|
line.split(' ')[0]
end
end

# Find Resque worker pids on Solaris.
#
# Returns an Array of string pids of all the other workers on this
# machine. Useful when pruning dead workers on startup.
def solaris_worker_pids
`ps -A -o pid,comm | grep [r]uby | grep -v "resque-web"`.split("\n").map do |line|
real_pid = line.split(' ')[0]
pargs_command = `pargs -a #{real_pid} 2>/dev/null | grep [r]esque | grep -v "resque-web"`
if pargs_command.split(':')[1] == " resque-#{Resque::Version}"
real_pid
end
end.compact
end

# Given a string, sets the procline ($0) and logs.
# Procline is always in the format of:
# resque-VERSION: STRING
Expand Down

0 comments on commit 6caf6b6

Please sign in to comment.