try new sync

This commit is contained in:
Seth Call 2021-01-11 12:15:15 -06:00
parent ee1dc427ce
commit 1eaaf8d4bf
5 changed files with 59 additions and 21 deletions

View File

@ -28,8 +28,6 @@ module JamRuby
def session_ratings(music_session, current_user, original_body)
begin
time = Time.now.utc.iso8601
my_data = original_body.delete('**me')
original_body.each do |k, other_data|
@ -37,17 +35,20 @@ module JamRuby
# we init passwordfield as a UUID, which is a bogus hash; so if we see UUId, we know retailer has no password yet
UUIDTools::UUID.parse(k)
other_user = User.find(k)
other_connection = Connection.find_by_client_id(k)
if other_connection
other_user = other_connection.user
body = {me: my_data, other: other_data}
body = {me: my_data, other: other_data}
body["@timestamp"] = Time.now.utc.iso8601
body["my_email"] = current_user.email
body["my_user_id"] = current_user.id
body["other_email"] = other_user.email
body["other_user_id"] = other_user.id
body["music_session_id"] = music_session.id
@client.index(id: "#{music_session.id}-#{current_user.id}-#{other_user.id}", index: MUSIC_SESSION_RATINGS, body: body)
body["@timestamp"] = Time.now.utc.iso8601
body["my_email"] = current_user.email
body["my_user_id"] = current_user.id
body["other_email"] = other_user.email
body["other_user_id"] = other_user.id
body["music_session_id"] = music_session.id
@client.index(id: "#{music_session.id}-#{current_user.id}-#{other_user.id}", index: MUSIC_SESSION_RATINGS, body: body)
end
rescue ArgumentError
# that's ok ; there are non-uuid keys in here; we ignore those
end
@ -56,6 +57,7 @@ module JamRuby
return true
rescue => e
@log.error("unable to parse session ratings #{e}")
puts("unable to parse session ratings #{e}")
return false
end

View File

@ -585,10 +585,19 @@ module JamRuby
else
if user.subscription_plan_code != user.desired_plan_code
puts "they are back! get them back into their desired plan #{user.email}"
user.subscription_plan_code = user.desired_plan_code
user.subscription_plan_code_set_at = DateTime.now
user.subscription_sync_code = 'good_standing_repaired'
user.subscription_sync_msg = "user is in good standing but desired != effective; plan_code set to #{user.desired_plan_code}"
if !SubscriptionDefinitions.is_downgrade(user.desired_plan_code, user.subscription_plan_code)
user.subscription_plan_code = user.desired_plan_code
user.subscription_plan_code_set_at = DateTime.now
user.subscription_sync_code = 'good_standing_repaired'
user.subscription_sync_msg = "user is in good standing but desired != effective; plan_code set to #{user.desired_plan_code}"
else
#user.subscription_plan_code = user.desired_plan_code
#user.subscription_plan_code_set_at = DateTime.now
user.subscription_sync_code = 'good_standing_ignored'
user.subscription_sync_msg = "user is in good standing but the desired plan is less than subscription plan; plan_code not touched"
end
else
puts "good standing user #{user.email} had no changes"
user.subscription_sync_code = 'good_standing_unchanged'

View File

@ -38,7 +38,8 @@ module JamRuby
max_players: 4,
pro_audio: false,
has_support: false,
name: 'Free'
name: 'Free',
rank: 0,
}
@ -56,7 +57,8 @@ module JamRuby
max_players: nil,
pro_audio: false,
has_support: false,
name: 'Silver'
name: 'Silver',
rank: 1,
}
GOLD_PLAN = {
@ -73,7 +75,8 @@ module JamRuby
max_players: nil,
pro_audio: true,
has_support: true,
name: 'Gold'
name: 'Gold',
rank: 2
}
PLATINUM_PLAN = {
@ -90,11 +93,12 @@ module JamRuby
max_players: nil,
pro_audio: true,
has_support: true,
name: 'Platinum'
name: 'Platinum',
rank: 3
}
def self.rules(plan_code)
if plan_code == nil
if plan_code == nil || plan_code == ''
FREE_PLAN
elsif plan_code == JAM_SILVER || plan_code == JAM_SILVER_YEARLY
SILVER_PLAN
@ -106,5 +110,12 @@ module JamRuby
raise "unknown plan #{plan_code}"
end
end
def self.is_downgrade(next_plan, current_plan)
next_plan_rank = rules(next_plan)[:rank]
current_plan_rank = rules(current_plan)[:rank]
next_plan_rank < current_plan_rank
end
end
end

View File

@ -0,0 +1,16 @@
require 'spec_helper'
describe SubscriptionDefinitions do
it "is downgrade " do
SubscriptionDefinitions.is_downgrade('jamsubgold', 'jamsubplatinum').should be_true
SubscriptionDefinitions.is_downgrade('jamsubplatinum', 'jamsubgold').should be_false
SubscriptionDefinitions.is_downgrade('jamsubgold', 'jamsubgold').should be_false
SubscriptionDefinitions.is_downgrade('jamsubgold', 'jamsubgoldyearly').should be_false
SubscriptionDefinitions.is_downgrade('jamsubgoldyearly', 'jamsubgold').should be_false
SubscriptionDefinitions.is_downgrade(nil, 'jamsubgold').should be_true
SubscriptionDefinitions.is_downgrade('jamsubsilver', nil).should be_false
SubscriptionDefinitions.is_downgrade('jamsubsilveryearly', nil).should be_false
end
end

View File

@ -440,7 +440,7 @@ class ApiMusicSessionsController < ApiController
succeeded = JamRuby::ElasticSearch.new.session_ratings(@history.music_session, current_user, backend_details)
body << succeeded ? "Stored in ElasticSearch" : "Unable to store in ElasticSearch!"
body << (succeeded ? "Stored in ElasticSearch" : "Unable to store in ElasticSearch!")
AdminMailer.jamclass_alerts({subject: subject, body: body}).deliver_now
rescue Exception => e
puts "Exception sending out ratings email. Boo #{e}"