Skip to content

Instantly share code, notes, and snippets.

@wzcolon
Created April 19, 2022 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wzcolon/8a8ea03a76dedd9f3937dc2c64ba6ecc to your computer and use it in GitHub Desktop.
Save wzcolon/8a8ea03a76dedd9f3937dc2c64ba6ecc to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module InsightfulAnalytics
class HourlyRevenueCalculationJob
#...
def perform(location_id, start_time)
@start_time = start_time
@location_id = location_id
return unless location
totals_by_op.each do |hash|
next if duplicate_present? (hash[:op_id])
# NOTE: notice create!
LogHourlyRevenueFluctuationsEvent.create!(
location: location,
ordering_platform_id: hash[:op_id],
start_datetime: start_datetime.beginning_of_hour,
total_revenue: hash[:total],
closed_ticket_count: hash[:closed_ticket_count]
)
rescue ActiveRecord::RecordInvalid
end
end
#...
end
end
class LogHourlyRevenueFluctuationEvent < ActiveRecord::Base
validates_uniquenss_of :start_datetime, { scope: [:location_id, :ordering_platform_id], message: "" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment