Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created August 19, 2011 19:45
Show Gist options
  • Save michaelfeathers/1157806 to your computer and use it in GitHub Desktop.
Save michaelfeathers/1157806 to your computer and use it in GitHub Desktop.
Slow Resque
def perform
@results ||= {}
puts "Looking up query"
query = Query.find_by_id(options["query_id"])
engine = Quote::Engine.create(query)
puts "Finding quotes"
quotes = engine.find_quotes(options["options"])
puts "Found quotes"
# NOTE:
# This is here so that sorting and filtering can take advantage
# of the unsorted/unfiltered data
puts "Merging quotes"
@results.merge!(
:no => quotes,
:yes => quotes
)
puts "Quotes merged"
puts "Sorting Quotes"
puts "There are #{quotes.size} quotes"
sorted_quotes = query.sort_results(quotes)
puts "Quotes Sorted"
filtered_quotes = @results.merge!(
:no => sorted_quotes,
:yes => query.filter_results(quotes)
)[options["options"][:filter]]
p filtered_quotes
puts "Running Quotes"
filtered_quotes.each_with_index do |quote,current|
at(current, quotes.size, "At #{current} of #{quotes.size}")
puts "Making json"
p quote.as_json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment