Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
Last active April 8, 2018 02:14
Show Gist options
  • Select an option

  • Save joeyAghion/9274268 to your computer and use it in GitHub Desktop.

Select an option

Save joeyAghion/9274268 to your computer and use it in GitHub Desktop.

Revisions

  1. joeyAghion revised this gist Nov 4, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -29,8 +29,8 @@
    # [["\nProblem:\n Validation of Artwork failed.\nSummary:\n The following errors were found: Unpublish requ",
    # 2]]]]

    # Grouped by method, approximately
    grouped = Delayed::Job.where(queue: 'any', priority: 3).group_by{|j| j.handler.match(/method_name: (.*)$/).try('[]', 1) || j.handler.inspect[0...50] }; pp grouped.map{|k,v| [k,v.size] }; nil
    # Counts by "method"
    grouped = Delayed::Job.where(queue: 'any', priority: 3).group_by{|j| j.handler.match(/method_name: (.*)$/).try('[]', 1) || j.handler.inspect[0...50] }; pp grouped.map{|k,v| [v.size,k] }.sort.reverse; nil
    # [[":end_show!", 2250],
    # [":start_show!", 1051],
    # [":welcome!", 17],
  2. joeyAghion revised this gist Oct 28, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -36,3 +36,7 @@
    # [":welcome!", 17],
    # [":set_default_image!", 2],
    # [":transfer_file_and_calculate_size!", 3]]

    # Counts by queue and priority excluding jobs scheduled for the future
    criteria = Delayed::Job.where(:run_at.lt => Time.now); pp criteria.distinct(:queue).sort.map{|q| criteria.where(queue: q).distinct(:priority).sort.map{|p| [q, p, criteria.where(queue: q, priority: p).count] } }.sort; nil
    # [[["any", 3, 1]], [["fair", 3, 536]]]
  3. joeyAghion revised this gist Oct 22, 2015. 1 changed file with 28 additions and 24 deletions.
    52 changes: 28 additions & 24 deletions delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,38 @@
    # Number of queued jobs per queue and priority
    pp Delayed::Job.distinct(:queue).sort.map{|q| Delayed::Job.where(queue: q).distinct(:priority).sort.map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil
    # [[["any", 2, 3], ["any", 3, 3323], ["any", 4, 5542], ["any", 5, 2]],
    # [["bidding", 3, 15]],
    # [["default", 3, 10]],
    # [["fair", 3, 246]]]

    # First 20 jobs, in order that workers dequeue them
    pp Delayed::Job.where(:run_at.lte => Time.now.utc, failed_at: nil).any_of({locked_by: /worker/}, {locked_at: nil}, {locked_at: {'$lt' => (Time.now.utc - 14400)}}).any_in(queue: %w{any imgs}).desc(:locked_by).asc(:priority).asc(:run_at).limit(20).map{|j| [j.id, j.handler.inspect[0..250], j.locked_by, j.run_at, (Time.now.utc - j.locked_at if j.locked_at)] }; nil
    # [[<BSON::ObjectId:0x135554220 data=5629067d7261696db2000040>,
    # "\"--- !ruby/object:Delayed::PerformableMethod\\nobject: !ruby/struct:Delayed::ShallowMongoid::DocumentStub\\n klass: !ruby/class 'Artwork'\\n id: 561fbb78726169264100002a\\n selector: \\nmethod_name: :es_update\\nargs: []\\n\"",
    # "delayed_job.gravity-4 host:worker8",
    # Thu, 22 Oct 2015 15:53:33 UTC +00:00,
    # 2.518255397],
    # ...

    # Failing jobs by queue and error start
    pp Delayed::Job.where(:last_error.exists => true).group_by{|j| [j.queue, j.priority] }.map{|(q,p),js| [q,p,js.group_by{|j| j.last_error[0...60]}.map{|err,jobs| [err,jobs.size] }] }; nil
    # [["any",
    # 3,
    # [["undefined method `artworks' for nil:NilClass\n/srv/www/gravity/releases/20151019161803/app/models/dom",
    # 1],
    # ["undefined method `artworks' for nil:NilClass\n/srv/www/gravity/releases/20151019161820/app/models/dom",
    # 1],
    # ["403 Forbidden\n/usr/local/lib/ruby/2.0.0/open-uri.rb:353:in `open_http'\n/usr/local/lib/ruby/2.0.0/ope",
    # 3]]],
    # ["any",
    # 5,
    # [["\nProblem:\n Validation of Artwork failed.\nSummary:\n The following errors were found: Unpublish requ",
    # 2]]]]

    #
    # Grouped by method, approximately
    grouped = Delayed::Job.where(queue: 'any', priority: 3).group_by{|j| j.handler.match(/method_name: (.*)$/).try('[]', 1) || j.handler.inspect[0...50] }; pp grouped.map{|k,v| [k,v.size] }; nil
    [["\"--- !ruby/struct:DelayedJobSessionProxy::DelayedJ", 44447],
    [":update_partner_artists", 2033],
    [":notify_published", 44],
    [":onboard!", 347],
    [":update_artists!", 227],
    [":invalidate_sale!", 203],
    [":update_for!", 94],
    [":remove_from_partner_shows!", 29],
    [":welcome!", 52],
    [":update_coordinates!", 15],
    [":update_auction_artists", 3],
    [":update_artist_auction_lots_count", 135],
    [":invalidate_related_profiles", 46],
    [":copy_image_to_user_icon!", 5],
    [":update_partner_shows!", 20],
    [":set_default_image!", 8],
    [":destroy_reposts!", 1],
    [":remind!", 2],
    [":generate_and_queue_daily_digest!", 1],
    [":update_artworks_batch", 1667],
    [":send!", 23],
    [":destroy_follows!", 3],
    [":update_partner_artist", 3]]
    # [[":end_show!", 2250],
    # [":start_show!", 1051],
    # [":welcome!", 17],
    # [":set_default_image!", 2],
    # [":transfer_file_and_calculate_size!", 3]]
  4. joeyAghion revised this gist Sep 5, 2014. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -6,3 +6,29 @@

    # Failing jobs by queue and error start
    pp Delayed::Job.where(:last_error.exists => true).group_by{|j| [j.queue, j.priority] }.map{|(q,p),js| [q,p,js.group_by{|j| j.last_error[0...60]}.map{|err,jobs| [err,jobs.size] }] }; nil

    #
    grouped = Delayed::Job.where(queue: 'any', priority: 3).group_by{|j| j.handler.match(/method_name: (.*)$/).try('[]', 1) || j.handler.inspect[0...50] }; pp grouped.map{|k,v| [k,v.size] }; nil
    [["\"--- !ruby/struct:DelayedJobSessionProxy::DelayedJ", 44447],
    [":update_partner_artists", 2033],
    [":notify_published", 44],
    [":onboard!", 347],
    [":update_artists!", 227],
    [":invalidate_sale!", 203],
    [":update_for!", 94],
    [":remove_from_partner_shows!", 29],
    [":welcome!", 52],
    [":update_coordinates!", 15],
    [":update_auction_artists", 3],
    [":update_artist_auction_lots_count", 135],
    [":invalidate_related_profiles", 46],
    [":copy_image_to_user_icon!", 5],
    [":update_partner_shows!", 20],
    [":set_default_image!", 8],
    [":destroy_reposts!", 1],
    [":remind!", 2],
    [":generate_and_queue_daily_digest!", 1],
    [":update_artworks_batch", 1667],
    [":send!", 23],
    [":destroy_follows!", 3],
    [":update_partner_artist", 3]]
  5. joeyAghion revised this gist Jun 25, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@

    # Number of queued jobs per queue and priority
    pp Delayed::Job.distinct(:queue).sort.map{|q| Delayed::Job.where(queue: q).distinct(:priority).sort.map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil

    # First 20 jobs, in order that workers dequeue them
    pp Delayed::Job.where(:run_at.lte => Time.now.utc, failed_at: nil).any_of({locked_by: /worker/}, {locked_at: nil}, {locked_at: {'$lt' => (Time.now.utc - 14400)}}).any_in(queue: %w{any imgs}).desc(:locked_by).asc(:priority).asc(:run_at).limit(20).map{|j| [j.id, j.handler.inspect[0..250], j.locked_by, j.run_at, (Time.now.utc - j.locked_at if j.locked_at)] }; nil

    # Failing jobs by queue and error start
    pp Delayed::Job.where(:last_error.exists => true).group_by{|j| [j.queue, j.priority] }.map{|(q,p),js| [q,p,js.group_by{|j| j.last_error[0...60]}.map{|err,jobs| [err,jobs.size] }] }; nil
  6. joeyAghion revised this gist Mar 19, 2014. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -1 +1,6 @@
    pp Delayed::Job.distinct(:queue).sort.map{|q| Delayed::Job.where(queue: q).distinct(:priority).sort.map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil

    # Number of queued jobs per queue and priority
    pp Delayed::Job.distinct(:queue).sort.map{|q| Delayed::Job.where(queue: q).distinct(:priority).sort.map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil

    # First 20 jobs, in order that workers dequeue them
    pp Delayed::Job.where(:run_at.lte => Time.now.utc, failed_at: nil).any_of({locked_by: /worker/}, {locked_at: nil}, {locked_at: {'$lt' => (Time.now.utc - 14400)}}).any_in(queue: %w{any imgs}).desc(:locked_by).asc(:priority).asc(:run_at).limit(20).map{|j| [j.id, j.handler.inspect[0..250], j.locked_by, j.run_at, (Time.now.utc - j.locked_at if j.locked_at)] }; nil
  7. joeyAghion revised this gist Mar 4, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion delayed_jobs_by_queue_and_priority.rb
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    pp Delayed::Job.distinct(:queue).map{|q| Delayed::Job.distinct(:priority).map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil
    pp Delayed::Job.distinct(:queue).sort.map{|q| Delayed::Job.where(queue: q).distinct(:priority).sort.map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil
  8. joeyAghion renamed this gist Feb 28, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. joeyAghion created this gist Feb 28, 2014.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    pp Delayed::Job.distinct(:queue).map{|q| Delayed::Job.distinct(:priority).map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil