Sha256: 0533deb5a6960f09e4cabc4003d9b705660c1beffa5978729a69370a1e3b4846

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
begin
  require 'redis-namespace'
rescue LoadError
  require 'rubygems'
  require 'redis-namespace'
end
require 'resque_admin'
require 'optparse'

parser = OptionParser.new do |opts|
  opts.banner = "Usage: resque_admin [options] COMMAND"

  opts.separator ""
  opts.separator "Options:"

  opts.on("-r", "--redis [HOST:PORT]", "Redis connection string") do |host|
    ResqueAdmin.redis = host
  end

  opts.on("-N", "--namespace [NAMESPACE]", "Redis namespace") do |namespace|
    ResqueAdmin.redis.namespace = namespace
  end

  opts.on("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  opts.separator ""
  opts.separator "Commands:"
  opts.separator "  remove WORKER   Removes a worker"
  opts.separator "  kill WORKER     Kills a worker"
  opts.separator "  list            Lists known workers"
end

def kill(worker)
  abort "** resque_admin kill WORKER_ID" if worker.nil?
  pid = worker.split(':')[1].to_i

  begin
    Process.kill("KILL", pid)
    puts "** killed #{worker}"
  rescue Errno::ESRCH
    puts "** worker #{worker} not running"
  end

  remove worker
end

def remove(worker)
  abort "** resque_admin remove WORKER_ID" if worker.nil?

  ResqueAdmin.remove_worker(worker)
  puts "** removed #{worker}"
end

def list
  if ResqueAdmin.workers.any?
    ResqueAdmin.workers.each do |worker|
      puts "#{worker} (#{worker.state})"
    end
  else
    puts "None"
  end
end

parser.parse!

case ARGV[0]
when 'kill'
  kill ARGV[1]
when 'remove'
  remove ARGV[1]
when 'list'
  list
else
  puts parser.help
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resque_admin-2.4.4 bin/resque-admin