Copy/paste snippets for managing prod incidents and data cleanup
Last active
March 16, 2026 21:20
-
-
Save patrick-boatner/4169f2a47676f768860f06ae2b67c65d to your computer and use it in GitHub Desktop.
Copy/paste snippets for managing prod incidents and data cleanup
This file contains hidden or 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
| # Other goodies here: | |
| # https://www.mikeperham.com/2021/04/20/a-tour-of-the-sidekiq-api/ | |
| q = Sidekiq::Queue.new("default") | |
| q = Sidekiq::Queue.new("low") | |
| q = Sidekiq::RetrySet.new | |
| q = Sidekiq::ScheduledSet.new | |
| pp q.map(&:klass).tally # get a quick overview of what's in the queue | |
| q.select do |job| | |
| # job.klass == 'My::WhateverJob' | |
| # job.item["error_class"] == 'My::WhateverError' | |
| # job.queue == 'low' | |
| # Not depicted: you should use q.scan for efficient server-side filtering | |
| end.each do |job| | |
| # job.jid job.klass job.args job.item["error_class"] job.queue job.item['error_message'] | |
| # puts "retrying job=#{job.jid} args=#{job.args} klass=#{job.klass}" | |
| # job.retry # for jobs in the retry queue, go ahead and run them | |
| # job.add_to_queue # for jobs in the scheduled queue, run them | |
| # job.delete # destructive | |
| # move to another queue | |
| # Sidekiq::Client.push( | |
| # 'class' => job.klass, | |
| # 'queue' => "low", # other queue name | |
| # 'args' => job.args | |
| # ) | |
| # job.delete | |
| end && nil |
This file contains hidden or 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
| def spotcheck_first_5(iterable) | |
| count = 1 | |
| iterable.each do |item| | |
| if count <= 5 | |
| puts "\nWe're about to process item #{item.inspect.truncate(80)}" | |
| print "Press enter to confirm" | |
| gets | |
| count += 1 | |
| end | |
| yield item | |
| end && nil | |
| end | |
| # instead of this... | |
| User.all.each do |u| | |
| puts "working on user=#{u.id}" | |
| end && nil | |
| # ...do this | |
| spotcheck_first_5(User.all.each) do |u| | |
| puts "working on user=#{u.id}" | |
| end |
This file contains hidden or 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
| # Export ActiveRecord relations | |
| # save into a standard CSV file | |
| def pluck_to_csv(results, *params) | |
| [params.join(",")].concat(results.pluck(*params).map { |o| o.join(",")}) | |
| end | |
| # copy/paste directly to a google sheet | |
| def pluck_to_tsv(results, *params) | |
| [params.join("\t")].concat(results.pluck(*params).map { |o| o.join("\t")}) | |
| end | |
| puts pluck_to_tsv(orders, :id, :external_order_id, :fulfillment_status, :paid_at, 'order_items.id') | |
| # Parse CSV file | |
| infos = [] | |
| CSV.foreach('/Users/locofocos/Downloads/whatever.csv', :headers => true) do |row| | |
| # liberal_parsing: true | |
| # puts row.headers | |
| infos << { | |
| ebay_id: row['Item number'], | |
| ebay_sku: row['Custom label (SKU)'] | |
| } | |
| end | |
| # Parse CSV from a URL | |
| require 'open-uri' | |
| require 'csv' | |
| download_url = "https://docs.google.com/spreadsheets/whatever" | |
| ids = [] | |
| # first = CSV.parse(URI.open(download_url), headers: true).first | |
| # CSV.foreach(open(download_url), headers: true) do |row| # breaks for smaller files?? StringIO vs String | |
| # ids << row['Listing ID'].to_i | |
| # end | |
| CSV.parse(URI.open(download_url), headers: true).each do |row| | |
| ids << row['product_id'].to_i | |
| end && nil | |
| # Paste multiple lines, parse to array | |
| input = <<HEREDOC | |
| paste stuff here | |
| HEREDOC | |
| ids = input.split("\n"); nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment