Commit a77239f2 authored by Piotr Skorupa's avatar Piotr Skorupa

Refactor handling Usage Ping response

parent dd292f11
......@@ -4,11 +4,7 @@ class RawUsageData < ApplicationRecord
validates :payload, presence: true
validates :recorded_at, presence: true, uniqueness: true
def update_sent_at!
self.update_column(:sent_at, Time.current)
end
def update_version_usage_data_id!(usage_data_id)
self.update_column(:version_usage_data_id_value, usage_data_id)
def update_version_metadata!(usage_data_id:)
self.update_columns(sent_at: Time.current, version_usage_data_id_value: usage_data_id)
end
end
......@@ -35,15 +35,10 @@ class SubmitUsagePingService
raise SubmissionError.new("Unsuccessful response code: #{response.code}") unless response.success?
RawUsageData.transaction do
if raw_usage_data
raw_usage_data.update_sent_at!
raw_usage_data.update_version_usage_data_id!(response.dig('conv_index', 'usage_data_id'))
end
raw_usage_data.update_version_metadata!(usage_data_id: response.dig('conv_index', 'usage_data_id'))
store_metrics(response)
end
end
private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment