Bug fixes for affiliate syncing

This commit is contained in:
Seth Call 2021-03-14 16:23:43 -05:00
parent f58be87187
commit 4dbf9fa17c
7 changed files with 18 additions and 16 deletions

View File

@ -14,13 +14,5 @@ module JamRuby
end
BAD_CONN_EXCEPTIONS.include?(test_exception.class)
end
def self.migrations_path
if ENV['RAILS_ENV'] == 'production'
"/var/lib/jam-web/vendor/bundle/ruby/2.3.0/gems/jam_ruby-0.1.#{ENV['BUILD_NUMBER']}/db/migrate"
else
File.expand_path("../../../../../db/migrate", __FILE__)
end
end
end
end

View File

@ -359,7 +359,7 @@ class JamRuby::AffiliatePartner < ActiveRecord::Base
UPDATE affiliate_monthly_payments
SET
closed = TRUE, closed_at = NOW()
WHERE year < #{year} OR month < #{month}
WHERE year < #{year} AND month < #{month}
}
ActiveRecord::Base.connection.execute(sql)

View File

@ -426,7 +426,7 @@ module JamRuby
def self.subscription_transaction_sync
recurly_client = RecurlyClient.new
last_sync_at = GenericState.recurly_transactions_last_sync_at
recurly_client.sync_transactions({ begin_time: last_sync_at.iso8601 })
recurly_client.sync_transactions({ begin_time: last_sync_at.nil? ? nil : last_sync_at.iso8601 })
end
def self.first_lesson_instructions

View File

@ -641,7 +641,8 @@ module JamRuby
def sync_transactions(options = {})
ActiveRecord::Base.transaction do
options.merge!({ sort: :updated_at, state: :successful })
options.merge!({ sort: :updated_at, state: :successful, per_page: 200 })
latest_seen = nil
Recurly::Transaction.find_each(options) do |transaction |
if AffiliateDistribution.find_by_external_id(transaction.uuid)
begin
@ -670,12 +671,19 @@ module JamRuby
fee_in_cents = transaction.amount_in_cents * affiliate_partner.rate
affiliate_distribution.affiliate_referral_fee_in_cents = fee_in_cents
affiliate_distribution.created_at = transaction.created_at.to_time
if latest_seen.nil? || latest_seen < transaction.created_at.to_time
latest_seen = transaction.created_at.to_time
end
affiliate_distribution.product_code = subscription.plan.plan_code
affiliate_distribution.external_id = transaction.uuid #external_id is a unique column. should raises error if duplicates
affiliate_distribution.save!
end
end
GenericState.singleton.update_attribute(:recurly_transactions_last_sync_at, Time.now)
# only grab the latest time as seen in the data; that way, we should never skip really recent entries if
if !latest_seen.nil?
GenericState.singleton.update_attribute(:recurly_transactions_last_sync_at, latest_seen)
end
end
end

View File

@ -12,6 +12,7 @@ module JamRuby
#LessonSession.hourly_check
#TeacherPayment.hourly_check
User.hourly_check
AffiliatePartner.tally_up(Date.today)
ConnectionManager.new.cleanup_dangling
@@log.info("done")

View File

@ -22,7 +22,7 @@ module JamRuby
def self.perform
@@log.debug("waking up")
AffiliatePartner.tally_up(Date.today)
#AffiliatePartner.tally_up(Date.today)
@@log.debug("done")
end

View File

@ -1,5 +1,6 @@
require "active_record"
require 'yaml'
require "yaml"
require "jam_ruby/rake_util"
namespace :db do
namespace :jam_ruby do
@ -22,7 +23,7 @@ namespace :db do
end
ActiveRecord::Base.establish_connection(db_config)
migrate_dir = JamRuby::DbUtil.migrations_path
migrate_dir = JamRuby::RakeUtil.migrations_path
ActiveRecord::Migrator.migrate(migrate_dir, version)
puts "#{ENV['RAILS_ENV']} database migrated."
end
@ -31,7 +32,7 @@ namespace :db do
task :rollback do
steps = (ARGV[1] || "1").to_i
ActiveRecord::Base.establish_connection(db_config)
migrate_dir = JamRuby::DbUtil.migrations_path
migrate_dir = JamRuby::RakeUtil.migrations_path
ActiveRecord::Migrator.rollback(migrate_dir, steps)
puts "#{ENV['RAILS_ENV']} database migrated."
end