Created
May 7, 2011 10:17
-
-
Save modsognir/960386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Resque | |
class Task | |
attr_accessor :parent, :args | |
attr_accessor :queue, :failed_at, :payload, :exception, :error, :backtrace, :worker | |
def initialize(options={}) | |
options['parent'] = options.delete('class') | |
options.each do |opt, val| | |
self.send("#{opt}=", val) | |
end | |
if payload | |
self.parent = payload['class'] | |
self.args = payload['args'] | |
end | |
end | |
def parent | |
@parent.constantize | |
end | |
def owner | |
# example use of args data | |
@owner ||= User.find(args[1]) if args[1].present? | |
end | |
class << self | |
def failed(start=0, finish=10000) | |
Resque::Failure.all(start, finish).map {|failure| Resque::Task.new(failure) } | |
end | |
def queued(start=0, finish=10000) | |
Resque.queues.map {|e| Resque.peek(e, start, finish) }.flatten.map {|task| Resque::Task.new(task) } | |
end | |
end | |
end | |
end | |
Resque::Task.queued.each do |task| | |
puts "Description: #{task.parent.to_s}" | |
puts "Object: #{task.args[0]}" | |
puts "Owner: #{task.owner.try(:username)}" | |
end | |
Resque::Task.failed.each do |task| | |
puts "Description: #{task.parent.to_s}" | |
puts "Object: #{task.args[0]}" | |
puts "Owner: #{task.owner.try(:username)}" | |
puts "Failed at: #{task.failed_at}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment