Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: resque/resque
head fork: thbar/resque
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 3 files changed
  • 6 commit comments
  • 1 contributor
Commits on Feb 26, 2010
@thbar thbar Fix undefined method `use_ssl=' for #<Net::HTTP b7dfb59
@thbar thbar Looks like the subdomain part is obsolete now. Note: this commit has …
…been done from GitHub web, so this requires a bit more testing!
Commits on Feb 27, 2010
@thbar thbar Allow to use a http proxy for hoptoad push. 33ecd23
Commits on Mar 01, 2010
@thbar thbar Fix #61 - use wmic instead of ps (only if use_wmic is enabled) for de…
…ad workers pruning. Use USE_WMIC=1 in ENV for resque:work to enable it.
25 lib/resque/failure/hoptoad.rb
@@ -1,5 +1,7 @@
require 'net/http'
+require 'net/https'
require 'builder'
+require 'uri'
module Resque
module Failure
@@ -10,18 +12,17 @@ module Failure
# Resque::Failure::Hoptoad.configure do |config|
# config.api_key = 'blah'
# = true
- # config.subdomain = 'your_hoptoad_subdomain'
+ #
+ # # optional proxy support
+ # config.proxy_host = 'x.y.z.t'
+ # config.proxy_port = 8080
# end
class Hoptoad < Base
#from the hoptoad plugin
INPUT_FORMAT = %r{^([^:]+):(\d+)(?::in `([^']+)')?$}.freeze
class << self
- attr_accessor :secure, :api_key, :subdomain
- end
- def self.url
- "http://#{subdomain}" if subdomain
+ attr_accessor :secure, :api_key, :proxy_host, :proxy_port
def self.count
@@ -35,13 +36,15 @@ def self.configure
Resque::Failure.backend = self
+ def request
+ use_proxy? ? Net::HTTP::Proxy(self.class.proxy_host, self.class.proxy_port) : Net::HTTP
+ end
def save
http = use_ssl? ? :https : :http
url = URI.parse("#{http}://")
- http =, url.port)
+ http =, url.port)
headers = {
'Content-type' => 'text/xml',
'Accept' => 'text/xml, application/xml'
@@ -51,7 +54,7 @@ def save
http.open_timeout = 2 # seconds
http.use_ssl = use_ssl?
response =, xml, headers)
rescue TimeoutError => e
@@ -110,6 +113,10 @@ def fill_in_backtrace_lines(x)
+ def use_proxy?
+ self.class.proxy_host
+ end
def use_ssl?
1  lib/resque/tasks.rb
@@ -15,6 +15,7 @@
worker =*queues)
worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
worker.very_verbose = ENV['VVERBOSE']
+ worker.use_wmic = ENV['USE_WMIC']
rescue Resque::NoQueueError
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
25 lib/resque/worker.rb
@@ -20,6 +20,9 @@ class Worker
# Automatically set if a fork(2) fails.
attr_accessor :cant_fork
+ # enables wmic process listing (useful on Windows where ps isn't there)
+ attr_accessor :use_wmic
attr_writer :to_s
# Returns an array of all worker objects.
@@ -408,13 +411,29 @@ def hostname
@hostname ||= `hostname`.chomp
- # Returns an array of string pids of all the other workers on this
- # machine. Useful when pruning dead workers on startup.
- def worker_pids
+ def ps_worker_pids
`ps -A -o pid,command | grep [r]esque`.split("\n").map do |line|
line.split(' ')[0]
+ def wmic_worker_pids
+ # notes:
+ # - not using backtick because it doesn't work on the author's machine
+ # - this can actually return more pids than expected, but this works.
+ # For instance I use FireDaemon to create Windows Services that shell
+ # out batch files that will appear. I have no reliable way to filter
+ # them out
+ IO.popen("wmic PROCESS get Processid,CommandLine /format:csv") do |f|
+ { |line| line.split(",")[2].strip }
+ end
+ end
+ # Returns an array of string pids of all the other workers on this
+ # machine. Useful when pruning dead workers on startup.
+ def worker_pids
+ use_wmic ? wmic_worker_pids : ps_worker_pids
+ end
# Given a string, sets the procline ($0) and logs.
# Procline is always in the format of:

Showing you all comments on commits in this comparison.


Is there any way that we can automatically detect that you should be using wmic? I'd love for this to "just work" without anyone having to set a setting.


Do you mean being able to provide a clever default (ie: on if probably required) and keep a way to switch it off ? I'd find it really nice as well.

Well out of my head, it could be something like:

  • try to run ps at startup, if it fails, try to run wmic, if it fails as well, fail-fast telling that either one or the other is needed. Failing if ps is not found would help ensure we don't have a weird behaviour in case the PATH is rotten, as well (although it's uncommon on *nix to not have ps handy)
  • or do more magic around rbconfig, with a bit of risk to be too clever and forget a use-case :)
  • in all cases, I'd keep some setting to let the use force the use of wmic.

These are raw thoughts but I really love your idea about "just work" by default.

What do you think ?


Does Windows have the type builtin or something similar?

$ type ps
ps is /bin/ps
$ type wmic
-bash: type: wmic: not found

Did a bit of research and found this:

> system("where ps")
Information : impossible de trouver ....
=> false

> system("where wmic")
=> true

It's quite close from a 'which' equivalent... Sounds like a good first candidate.

General thought on all this: I'd +1 on fail-fast approach for system calls (backtick or others) to avoid difficult to track bugs (ex: we discover that 'where' is not available on Windows X.Y). For instance, I use this often:

def system!(cmd)
  raise "Error while launching #{cmd}" unless system(cmd)

Haa - I've been bitten by exactly this, I think. I needed to test if the worker service would run properly under a different account (named LocalSystem on windows). Wmic not being found led to weird errors (like: the service runs, but is not registered at all etc).

Weirdness weirdness :)

What's your take on this, should we check the commands existence beforehand ?


I too am trying to run this under Windows and the most direct solution is to add ps to your Windows box.

Install "Subsystem for UNIX-based Applications (SUA)" role that ships with Windows Server 2008 [R2], then install the "Utilities and SDK" downloadable component:

Utilities and SDK for Subsystem for UNIX-based Applications in Microsoft Windows Vista RTM/Windows Vista SP1 and Windows Server 2008 RTM

Utilities and Software Development Kit (SDK) for Subsystem for UNIX-based Applications (for Windows Server 2008 R2)

Something went wrong with that request. Please try again.