Skip to content

Commit

Permalink
fix(clickhouse): pay in advance handling (#2724)
Browse files Browse the repository at this point in the history
This PR fixes the handling of events for pay in advance charges with
both `Clickhouse` and the ingest service
  • Loading branch information
vincent-pochet authored Oct 22, 2024
1 parent 81eb7bd commit aa3c89d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/services/billable_metrics/aggregation_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def supports_clickhouse?
def self.new_instance(charge:, current_usage: false, **attributes)
event_store = Events::Stores::PostgresStore

if !charge.pay_in_advance? && supports_clickhouse? && charge.billable_metric.organization.clickhouse_events_store?
if supports_clickhouse? && charge.billable_metric.organization.clickhouse_events_store?
event_store = Events::Stores::ClickhouseStore
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/events/common_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.new_instance(source:)
organization_id: source['organization_id'],
transaction_id: source['transaction_id'],
external_subscription_id: source['external_subscription_id'],
timestamp: Time.zone.at(source['timestamp'].to_f),
timestamp: Time.zone.at(source['timestamp'].to_i),
code: source['code'],
properties: source['properties']
)
Expand Down
2 changes: 1 addition & 1 deletion app/services/events/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def produce_kafka_event(event)
external_subscription_id: event.external_subscription_id,
transaction_id: event.transaction_id,
# NOTE: Removes trailing 'Z' to allow clickhouse parsing
timestamp: event.timestamp.iso8601[...-1],
timestamp: event.timestamp.to_i,
code: event.code,
# NOTE: Default value to 0.0 is required for clickhouse parsing
precise_total_amount_cents: event.precise_total_amount_cents.present? ? event.precise_total_amount_cents.to_s : "0.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/services/events/common_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
expect(new_instance.organization_id).to eq(source['organization_id'])
expect(new_instance.transaction_id).to eq(source['transaction_id'])
expect(new_instance.external_subscription_id).to eq(source['external_subscription_id'])
expect(new_instance.timestamp).to eq(Time.zone.at(source['timestamp'].to_f))
expect(new_instance.timestamp).to eq(Time.zone.at(source['timestamp'].to_i))
expect(new_instance.code).to eq(source['code'])
expect(new_instance.properties).to eq(source['properties'])
end
Expand Down

0 comments on commit aa3c89d

Please sign in to comment.