Skip to content

Commit

Permalink
Fix the ImportWorker (#61)
Browse files Browse the repository at this point in the history
* Fix the ImportWorker
* Move start date to model
  • Loading branch information
forsbergplustwo authored Aug 23, 2023
1 parent 8d23a10 commit 5b223ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/models/payment_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ class PaymentHistory < ActiveRecord::Base
validates :user_id, presence: true

class << self
def default_start_date
4.years.ago.to_date
end

def import_csv(current_user, last_calculated_metric_date, filename)
temp = Tempfile.new("import")
s3 = Aws::S3::Client.new
Expand Down Expand Up @@ -349,7 +353,7 @@ def calculate_metrics(current_user)
elsif current_user.payment_histories.any?
current_user.payment_histories.order("payment_date").first.payment_date
else
6.months.ago.to_date
PaymentHistory.default_start_date
end
Rails.logger.info(calculate_from)
last_imported_payment = current_user.payment_histories.maximum(:payment_date)
Expand Down
6 changes: 3 additions & 3 deletions app/workers/import_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def self.perform(current_user_id, filename = nil)
return unless current_user_id

current_user = User.find(current_user_id)
last_calculated_metric = current_user.newest_metric_date || 48.months.ago.to_date
last_calculated_metric = current_user.newest_metric_date || PaymentHistory.default_start_date

if !filename.nil?
PaymentHistory.import_csv(current_user, last_calculated_metric_date, filename)
PaymentHistory.import_csv(current_user, last_calculated_metric, filename)
else
PaymentHistory.import_partner_api(current_user, last_calculated_metric_date)
PaymentHistory.import_partner_api(current_user, last_calculated_metric)
end

# Payments must be imported fully before metrics can be calculated
Expand Down

0 comments on commit 5b223ee

Please sign in to comment.