Created
April 19, 2022 20:28
-
-
Save wzcolon/8a8ea03a76dedd9f3937dc2c64ba6ecc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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