Skip to content

Instantly share code, notes, and snippets.

@Koronen
Last active August 29, 2015 13:57

Revisions

  1. Koronen revised this gist Jun 9, 2015. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,14 @@
    puts fbe.map { |e,jj| [e, jj.size] }.inspect
    puts fbc.map { |e,jj| [e, jj.size] }.inspect

    # Dump as JSON
    # Dump failures as JSON
    failures = Resque::Failure.all(0, -1).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    File.open("resque_failures_#{Time.now.strftime("%FT%T")}.json", 'wb') { |f| f.write JSON.dump(failures) }

    # Dump low queue as JSON
    low = Resque.redis.lrange 'queue:low', 0, -1; nil
    File.open("low_#{Time.now.strftime("%FT%T")}.json", "wb") { |f| f.write JSON.dump(low.map{|x| JSON.parse(x)}) }

    # Remove duplicates(?)
    key = 'queue:low'
    members = Resque.redis.lrange(key, 0, -1)
  2. Koronen revised this gist Jun 9, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    # Print statistics
    failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    failures = Resque::Failure.all(0, -1).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    fbe = Hash.new { |h, k| h[k] = Array.new }
    fbc = Hash.new { |h, k| h[k] = Array.new }
    failures.each { |ex| fbe[ex['exception']] << ex; fbc[ex['payload']['class']] << ex }; nil
    puts fbe.map { |e,jj| [e, jj.size] }.inspect
    puts fbc.map { |e,jj| [e, jj.size] }.inspect

    # Dump as JSON
    failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    File.open("resque_failures_#{Time.now.iso8601}.json", 'wb') { |f| f.write JSON.dump(failures) }
    failures = Resque::Failure.all(0, -1).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    File.open("resque_failures_#{Time.now.strftime("%FT%T")}.json", 'wb') { |f| f.write JSON.dump(failures) }

    # Remove duplicates(?)
    key = 'queue:low'
  3. Koronen revised this gist Feb 3, 2015. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,16 @@

    # Dump as JSON
    failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    File.open("resque_failures_#{Time.now.iso8601}.json", 'wb') { |f| f.write JSON.dump(failures) }
    File.open("resque_failures_#{Time.now.iso8601}.json", 'wb') { |f| f.write JSON.dump(failures) }

    # Remove duplicates(?)
    key = 'queue:low'
    members = Resque.redis.lrange(key, 0, -1)
    duplicate_members = members.group_by { |e| e }.select { |k, v| v.size > 1 }.map(&:first)
    if duplicate_members.count > 0
    puts "#{key}: has #{duplicate_members.count} duplicates"
    duplicate_members.each do |duplicate_member|
    puts "Removing #{duplicate_member}"
    Resque.redis.lrem(key, -1, duplicate_member)
    end
    end
  4. Koronen revised this gist Jan 13, 2015. 1 changed file with 6 additions and 25 deletions.
    31 changes: 6 additions & 25 deletions resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,11 @@
    def failures_with_ids(n)
    Resque::Failure.all(0,n).each_with_index.map { |ex, i| ex['id'] = i; ex }
    end

    def group_by_exception(failures)
    failures.reduce({}) do |acc, ex|
    acc[ex['exception']] ||= []
    acc[ex['exception']] << ex
    acc
    end
    end

    def group_by_class(failures)
    failures.reduce({}) do |acc, ex|
    acc[ex['payload']['class']] ||= []
    acc[ex['payload']['class']] << ex
    acc
    end
    end

    def value_counts(grouped_failures)
    Hash[grouped_failures.map { |key, exs| [key, exs.size] }]
    end

    # Print statistics
    failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    fbe = Hash.new { |h, k| h[k] = Array.new }
    fbc = Hash.new { |h, k| h[k] = Array.new }
    failures.each { |ex| fbe[ex['exception']] << ex; fbc[ex['payload']['class']] << ex }; nil
    puts fbe.map { |e,jj| [e, jj.size] }.inspect
    puts fbc.map { |e,jj| [e, jj.size] }.inspect
    puts fbc.map { |e,jj| [e, jj.size] }.inspect

    # Dump as JSON
    failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    File.open("resque_failures_#{Time.now.iso8601}.json", 'wb') { |f| f.write JSON.dump(failures) }
  5. Koronen revised this gist Dec 31, 2014. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,11 @@ def group_by_class(failures)

    def value_counts(grouped_failures)
    Hash[grouped_failures.map { |key, exs| [key, exs.size] }]
    end
    end

    failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
    fbe = Hash.new { |h, k| h[k] = Array.new }
    fbc = Hash.new { |h, k| h[k] = Array.new }
    failures.each { |ex| fbe[ex['exception']] << ex; fbc[ex['payload']['class']] << ex }; nil
    puts fbe.map { |e,jj| [e, jj.size] }.inspect
    puts fbc.map { |e,jj| [e, jj.size] }.inspect
  6. Koronen revised this gist Mar 24, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -19,5 +19,5 @@ def group_by_class(failures)
    end

    def value_counts(grouped_failures)
    Hash[grouped_failure.map { |key, exs| [key, exs.size] }]
    Hash[grouped_failures.map { |key, exs| [key, exs.size] }]
    end
  7. Koronen revised this gist Mar 24, 2014. 1 changed file with 21 additions and 3 deletions.
    24 changes: 21 additions & 3 deletions resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,23 @@
    failures_with_ids = Resque::Failure.all(0,13000).each_with_index.map { |ex, i| ex['id'] = i; ex }
    def failures_with_ids(n)
    Resque::Failure.all(0,n).each_with_index.map { |ex, i| ex['id'] = i; ex }
    end

    failure_grouped_by_exception = failures_with_ids.reduce({}){|acc, ex| acc[ex['exception']] ||= []; acc[ex['exception']] << ex; acc }
    def group_by_exception(failures)
    failures.reduce({}) do |acc, ex|
    acc[ex['exception']] ||= []
    acc[ex['exception']] << ex
    acc
    end
    end

    failure_grouped_by_class = failures_with_ids.reduce({}){|acc, ex| acc[ex['payload']['class']] ||= []; acc[ex['payload']['class']] << ex; acc }
    def group_by_class(failures)
    failures.reduce({}) do |acc, ex|
    acc[ex['payload']['class']] ||= []
    acc[ex['payload']['class']] << ex
    acc
    end
    end

    def value_counts(grouped_failures)
    Hash[grouped_failure.map { |key, exs| [key, exs.size] }]
    end
  8. Koronen created this gist Mar 24, 2014.
    5 changes: 5 additions & 0 deletions resque-stat-hacks.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    failures_with_ids = Resque::Failure.all(0,13000).each_with_index.map { |ex, i| ex['id'] = i; ex }

    failure_grouped_by_exception = failures_with_ids.reduce({}){|acc, ex| acc[ex['exception']] ||= []; acc[ex['exception']] << ex; acc }

    failure_grouped_by_class = failures_with_ids.reduce({}){|acc, ex| acc[ex['payload']['class']] ||= []; acc[ex['payload']['class']] << ex; acc }