* VRFS-3212 - track counts of concurrent packaging attempts

This commit is contained in:
Seth Call 2015-05-07 08:49:15 -05:00
parent f593a6d706
commit 12eeb460a3
10 changed files with 88 additions and 11 deletions

View File

@ -282,3 +282,4 @@ first_played_jamtrack_at.sql
payment_history.sql
jam_track_right_private_key.sql
first_downloaded_jamtrack_at.sql
signing.sql

2
db/up/signing.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE jam_track_rights ADD COLUMN signing_44 BOOLEAN DEFAULT FALSE;
ALTER TABLE jam_track_rights ADD COLUMN signing_48 BOOLEAN DEFAULT FALSE;

View File

@ -53,12 +53,18 @@ module JamRuby
JamTrackRight.where("downloaded_since_sign=? AND updated_at <= ?", true, 5.minutes.ago).limit(1000)
end
def finish_errored(error_reason, error_detail)
def finish_errored(error_reason, error_detail, sample_rate)
self.last_signed_at = Time.now
self.error_count = self.error_count + 1
self.error_reason = error_reason
self.error_detail = error_detail
self.should_retry = self.error_count < 5
if sample_rate == 48
self.signing_48 = false
else
self.signing_44 = false
end
if save
Notification.send_jam_track_sign_failed(self)
else
@ -72,10 +78,12 @@ module JamRuby
self.length_48 = length
self.md5_48 = md5
self.signed_48 = true
self.signing_48 = false
else
self.length_44 = length
self.md5_44 = md5
self.signed_44 = true
self.signing_44 = false
end
self.error_count = 0
self.error_reason = nil
@ -202,6 +210,17 @@ module JamRuby
.joins("LEFT OUTER JOIN jam_track_rights ON jam_tracks.id = jam_track_rights.jam_track_id AND jam_track_rights.user_id = '#{user.id}'")
.where('jam_tracks.id IN (?)', jamtracks)
end
def self.stats
stats = {}
result = JamTrackRight.select('count(id) as total, count(CASE WHEN signing_44 THEN 1 ELSE NULL END) + count(CASE WHEN signing_48 THEN 1 ELSE NULL END) as signing_count, count(CASE WHEN redeemed THEN 1 ELSE NULL END) as redeem_count').where(is_test_purchase: false).first
stats['count'] = result['total'].to_i
stats['signing_count'] = result['signing_count'].to_i
stats['redeemed_count'] = result['redeem_count'].to_i
stats['purchased_count'] = stats['count'] - stats['redeemed_count']
stats
end
end
end

View File

@ -40,12 +40,14 @@ module JamRuby
# track that it's started ( and avoid db validations )
signing_started_at = Time.now
signing_started_model_symbol = bitrate == 48 ? :signing_started_at_48 : :signing_started_at_44
signing_state_symbol = bitrate == 48 ? :signing_48 : :signing_44
last_step_at = Time.now
JamTrackRight.where(:id => @jam_track_right.id).update_all(signing_started_model_symbol => signing_started_at, :should_retry => false, packaging_steps: total_steps, current_packaging_step: 0, last_step_at: last_step_at)
JamTrackRight.where(:id => @jam_track_right.id).update_all(signing_started_model_symbol => signing_started_at, :should_retry => false, packaging_steps: total_steps, current_packaging_step: 0, last_step_at: last_step_at, signing_state_symbol => true)
# because we are skipping 'after_save', we have to keep the model current for the notification. A bit ugly...
@jam_track_right.current_packaging_step = 0
@jam_track_right.packaging_steps = total_steps
@jam_track_right[signing_started_model_symbol] = signing_started_at
@jam_track_right[signing_state_symbol] = true
@jam_track_right.should_retry = false
@jam_track_right.last_step_at = Time.now
SubscriptionMessage.jam_track_signing_job_change(@jam_track_right)
@ -75,7 +77,7 @@ module JamRuby
@error_reason = "unhandled-job-exception"
@error_detail = e.to_s
end
@jam_track_right.finish_errored(@error_reason, @error_detail)
@jam_track_right.finish_errored(@error_reason, @error_detail, self.bitrate)
rescue Exception => e
log.error "unable to post back to the database the error #{e}"

View File

@ -30,6 +30,7 @@ module JamRuby
Stats.write('connection', Connection.stats)
Stats.write('users', User.stats)
Stats.write('sessions', ActiveMusicSession.stats)
Stats.write('jam_track_rights', JamTrackRight.stats)
end
end

View File

@ -761,6 +761,8 @@ FactoryGirl.define do
factory :jam_track_right, :class => JamRuby::JamTrackRight do
association :jam_track, factory: :jam_track
association :user, factory: :user
signing_44 false
signing_48 false
end
factory :jam_track_tap_in, :class => JamRuby::JamTrackTapIn do

View File

@ -155,5 +155,58 @@ describe JamTrackRight do
end
end
describe "stats" do
it "empty" do
JamTrackRight.stats['count'].should eq(0)
end
it "one" do
right1 = FactoryGirl.create(:jam_track_right)
JamTrackRight.stats.should eq('count' => 1,
'signing_count' => 0,
'redeemed_count' => 0,
'purchased_count' => 1)
end
it "two" do
right1 = FactoryGirl.create(:jam_track_right)
right2 = FactoryGirl.create(:jam_track_right)
JamTrackRight.stats.should eq('count' => 2,
'signing_count' => 0,
'redeemed_count' => 0,
'purchased_count' => 2)
right1.signing_44 = true
right1.save!
right2.signing_48 = true
right2.save!
JamTrackRight.stats.should eq('count' => 2,
'signing_count' => 2,
'redeemed_count' => 0,
'purchased_count' => 2)
right1.redeemed = true
right1.save!
JamTrackRight.stats.should eq('count' => 2,
'signing_count' => 2,
'redeemed_count' => 1,
'purchased_count' => 1)
right2.is_test_purchase = true
right2.save!
JamTrackRight.stats.should eq('count' => 1,
'signing_count' => 1,
'redeemed_count' => 1,
'purchased_count' => 0)
end
end
end

View File

@ -31,6 +31,9 @@ context.JK.JamTrackScreen=class JamTrackScreen
this.refresh()
).fail((arg) =>
@logger.error("app.user.done failed: " + JSON.stringify(arg))
@logger.debug(arg.statusCode);
throw 'fail should not occur if user is available'
)
else

View File

@ -219,7 +219,7 @@ if defined?(Bundler)
# amount of time before we think the queue is stuck
config.signing_job_queue_max_time = 20 # 20 seconds
# amount of time to allow before giving up on a single step in packaging job
config.signing_step_max_time = 40; # 40 seconds
config.signing_step_max_time = 60; # 60 seconds
config.email_alerts_alias = 'alerts@jamkazam.com' # should be used for 'oh no' server down/service down sorts of emails
config.email_generic_from = 'nobody@jamkazam.com'

View File

@ -172,9 +172,6 @@ describe ApiJamTracksController do
response.location.should =~ /.*#{Regexp.escape(right.filename(:url_48))}.*/
right.reload
right.download_count.should eq(1)
notifications = Notification.where(:jam_track_right_id=>right.id)
notifications.count.should == 1
end
it "supports multiple bitrates" do
@ -206,9 +203,6 @@ describe ApiJamTracksController do
response.location.should =~ /.*#{Regexp.escape(right.filename(:url_44))}.*/
right.reload
right.download_count.should eq(1)
notifications = Notification.where(:jam_track_right_id=>right.id)
notifications.count.should == 1
end
end