Skip to content

Commit

Permalink
Remove debugging tools
Browse files Browse the repository at this point in the history
  • Loading branch information
svevang committed Nov 11, 2024
1 parent 667c130 commit 3ded83d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
55 changes: 5 additions & 50 deletions app/models/apple/episode_delivery_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,16 @@ module Apple
class EpisodeDeliveryStatus < ApplicationRecord
belongs_to :episode, -> { with_deleted }, class_name: "::Episode"

def self.change_log(apple_episode_delivery_statuses)
return [] unless apple_episode_delivery_statuses&.any?

statuses = apple_episode_delivery_statuses.to_a
changes = []

tracked_attributes = column_names - ["id", "created_at"]

latest_values = {}

statuses.reverse_each do |status|
tracked_attributes.each do |attr|
value = status.send(attr)

# Only record the change if we haven't seen this attribute before
# or if the value is different from the most recent one
if !latest_values.key?(attr) || latest_values[attr] != value
latest_values[attr] = value

# Format the change message
message = format_change_message(attr, value, status.created_at)
changes.unshift(message) unless message.nil?
end
end
end

changes
end

def self.format_change_message(attribute, value, timestamp)
return nil if value.nil?

formatted_time = timestamp.strftime("%Y-%m-%d %H:%M:%S")
"#{formatted_time}: #{attribute.humanize} changed to #{value}"
end

def self.measure_asset_processing_duration(apple_episode_delivery_statuses, relative_timestamp)
return [] unless apple_episode_delivery_statuses&.any?

def self.measure_asset_processing_duration(apple_episode_delivery_statuses)
statuses = apple_episode_delivery_statuses.to_a

last_status = statuses.shift
return nil unless last_status&.asset_processing_attempts.to_i.positive?

return [nil, measure_asset_processing_duration(statuses, last_status.created_at)].flatten unless last_status&.asset_processing_attempts.to_i.positive?

end_status = while (status = statuses.shift)
break status if status.asset_processing_attempts.to_i.zero?
end

return [nil].flatten unless end_status
start_status = statuses.find { |status| status.asset_processing_attempts.to_i.zero? }
return nil unless start_status

[
relative_timestamp - end_status.created_at,
measure_asset_processing_duration(statuses, end_status.created_at)
].flatten
Time.now - start_status.created_at
end

def self.update_status(episode, attrs)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/apple_delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def apple_has_delivery!
end

def measure_asset_processing_duration
Apple::EpisodeDeliveryStatus.measure_asset_processing_duration(apple_episode_delivery_statuses, Time.now.utc).first
Apple::EpisodeDeliveryStatus.measure_asset_processing_duration(apple_episode_delivery_statuses)
end

def apple_prepare_for_delivery!
Expand Down

0 comments on commit 3ded83d

Please sign in to comment.