Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task to print Subscriptions debug info #6293

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lib/tasks/subscriptions/debug.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

# rubocop:disable Metrics/BlockLength
namespace :ofn do
namespace :subs do
namespace :debug do
desc "Print standard info about a specific Order Cycle"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
task order_cycle: :environment do
order_cycle_id = request_order_cycle_id

order_cycle = OrderCycle.find_by(id: order_cycle_id)
puts "Order Cycle #{order_cycle.name}"
order_cycle.schedules.each do |schedule|
puts "Schedule #{schedule.name}"
Subscription.where(schedule_id: schedule.id).each do |subscription|
puts
puts "Subscription #{subscription.id}"
puts subscription.shop.name
puts subscription.customer.email
puts subscription.payment_method.name
puts "Active from #{subscription.begins_at} to #{subscription.ends_at}"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
puts "Last edited on #{subscription.updated_at}"
puts "Canceled at #{subscription.canceled_at} and paused at #{subscription.paused_at}"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved

ProxyOrder.where(order_cycle_id: order_cycle_id,
subscription_id: subscription.id).each do |proxy_order|
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@sauloperez sauloperez Nov 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should stay on the safe side with all these DB fetches using find_each and avoid potential problems in the future with all these nested iterations loading all these objects. I'm happy to go on with this and fix it in a separate PR myself.

puts
puts "Proxy Order #{proxy_order.id}"
puts "Canceled at #{proxy_order.canceled_at}"
puts "Last updated at #{proxy_order.updated_at}"
puts "Placed at #{proxy_order.placed_at}"
puts "Confirmed at #{proxy_order.confirmed_at}"

puts
puts "Order #{proxy_order.order_id} - #{proxy_order.order.number}"
puts "Order is #{proxy_order.order.state} with total #{proxy_order.order.total}"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
proxy_order.order.payments.each do |payment|
puts "Payment #{payment.id} with state #{payment.state}"
puts "Amount #{payment.amount}"
puts "Source #{payment.source_type} #{payment.source_id}"
if payment.source_type == "Spree::CreditCard"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
puts "Source #{payment.source.to_json}"
end
Spree::LogEntry.where(source_type: "Spree::Payment",
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
source_id: payment.id).each do |log_entry|
puts "Log Entries found"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
puts log_entry.details
end
end
end
end
end
end

def request_order_cycle_id
puts "Please input Order Cycle ID to debug"
andrewpbrett marked this conversation as resolved.
Show resolved Hide resolved
input = STDIN.gets.chomp
exit if input.blank? || !Integer(input)
Integer(input)
end
end
end
end
# rubocop:enable Metrics/BlockLength