MT#14255 notopup_expiry calculation only when required

Change-Id: I79acf1acea6174e4d9f72fccfa01ad9196833fd4
changes/09/2709/1
Rene Krenn 10 years ago
parent 968ed762e6
commit 25f54603fb

@ -196,23 +196,14 @@ sub catchup_contract_balances {
#$c->log->debug('catchup contract ' . $contract->id . ' contract_balances (now = ' . NGCP::Panel::Utils::DateTime::to_string($now) . ')') if $c;
my ($start_mode,$interval_unit,$interval_value,$carry_over_mode,$has_package,$notopup_expiration,$underrun_profile_threshold,$underrun_lock_threshold);
my ($start_mode,$interval_unit,$interval_value,$carry_over_mode,$has_package,$notopup_discard_intervals,$underrun_profile_threshold,$underrun_lock_threshold);
if (defined $contract->contact->reseller_id && $old_package) {
$start_mode = $old_package->balance_interval_start_mode;
$interval_unit = $old_package->balance_interval_unit;
$interval_value = $old_package->balance_interval_value;
$carry_over_mode = $old_package->carry_over_mode;
my $notopup_discard_intervals = $old_package->notopup_discard_intervals;
if ($notopup_discard_intervals) {
#take the start of the latest interval where a topup occured,
#add the allowed number+1 of the current package' intervals.
#the balance is discarded if the start of the next package
#exceed this calculated expiration date.
my $last_balance_w_topup = $contract->contract_balances->search({ topup_count => { '>' => 0 } },{ order_by => { '-desc' => 'end'},})->first;
$last_balance_w_topup = $contract->contract_balances->search(undef,{ order_by => { '-asc' => 'start'},})->first unless $last_balance_w_topup;
$notopup_expiration = _add_interval($last_balance_w_topup->start,$interval_unit,$notopup_discard_intervals + 1) if $last_balance_w_topup;
}
$notopup_discard_intervals = $old_package->notopup_discard_intervals;
$underrun_profile_threshold = $old_package->underrun_profile_threshold;
$underrun_lock_threshold = $old_package->underrun_lock_threshold;
$has_package = 1;
@ -223,12 +214,21 @@ sub catchup_contract_balances {
}
my ($underrun_lock_applied,$underrun_profiles_applied) = (0,0);
my ($notopup_expiration,$is_notopup_expiration_calculated) = (undef,0);
my $last_balance = $contract->contract_balances->search(undef,{ order_by => { '-desc' => 'end'},})->first;
my $last_profile;
while ($last_balance && !NGCP::Panel::Utils::DateTime::is_infinite_future($last_balance->end) && $last_balance->end < $now) { #comparison takes 100++ sec if loaded lastbalance contains +inf
my $start_of_next_interval = $last_balance->end->clone->add(seconds => 1);
unless ($is_notopup_expiration_calculated) {
#we have two queries here, so do it only if really creating contract_balances
$notopup_expiration = _get_notopup_expiration(contract => $contract,
notopup_discard_intervals => $notopup_discard_intervals,
interval_unit => $interval_unit);
$is_notopup_expiration_calculated = 1;
}
my $bm_actual;
unless ($last_profile) {
$bm_actual = get_actual_billing_mapping(schema => $schema, contract => $contract, now => $last_balance->start);
@ -248,7 +248,7 @@ PREPARE_BALANCE_CATCHUP:
interval_unit => $interval_unit,
interval_value => $interval_value,
create => $contract_create);
my $balance_values = _get_balance_values(schema => $schema,
stime => $stime,
etime => $etime,
@ -671,6 +671,22 @@ sub _add_interval {
return undef;
}
sub _get_notopup_expiration {
my %params = @_;
my($contract,$notopup_discard_intervals,$interval_unit)= @params{qw/contract notopup_discard_intervals interval_unit/};
my $notopup_expiration = undef;
if ($notopup_discard_intervals) {
#take the start of the latest interval where a topup occured,
#add the allowed number+1 of the current package' intervals.
#the balance is discarded if the start of the next package
#exceed this calculated expiration date.
my $last_balance_w_topup = $contract->contract_balances->search({ topup_count => { '>' => 0 } },{ order_by => { '-desc' => 'end'},})->first;
$last_balance_w_topup = $contract->contract_balances->search(undef,{ order_by => { '-asc' => 'start'},})->first unless $last_balance_w_topup;
$notopup_expiration = _add_interval($last_balance_w_topup->start,$interval_unit,$notopup_discard_intervals + 1) if $last_balance_w_topup;
}
return $notopup_expiration;
}
sub get_actual_billing_mapping {
my %params = @_;
my ($c,$schema,$contract,$now) = @params{qw/c schema contract now/};

@ -1 +1 @@
PERL5LIB=/opt/Komodo-IDE-9/remote_debugging PERLDB_OPTS="RemotePort=127.0.0.1:9000" DBGP_IDEKEY="jdoe" CATALYST_DEBUG=1 DBIC_TRACE=1 DBIC_TRACE_PROFILE=console DEVEL_CONFESS_OPTIONS='objects builtin dump color source' perl -d `which plackup` -I ../data-hal/lib -I ../ngcp-schema/lib -I lib -I ../sipwise-base/lib/ ngcp_panel.psgi --listen /tmp/ngcp_panel_sock --nproc 4 -s FCGI -r
PERL5LIB=/opt/Komodo-IDE-9/remote_debugging PERLDB_OPTS="RemotePort=127.0.0.1:9000" DBGP_IDEKEY="jdoe" CATALYST_DEBUG=1 DBIC_TRACE=1 DBIC_TRACE_PROFILE=console DEVEL_CONFESS_OPTIONS='objects builtin dump color source' perl -d `which plackup` -I ../data-hal/lib -I ../ngcp-schema/lib -I lib -I ../sipwise-base/lib/ ngcp_panel.psgi --listen /tmp/ngcp_panel_sock --nproc 2 -s FCGI -r

@ -941,7 +941,7 @@ if (_get_allow_fake_client_time() && $enable_profile_packages) {
_set_time();
my $t1 = time;
my $delay = 10; #15;
my $delay = 20; #15;
my $t_a = threads->create(\&_fetch_intervals_worker,$delay,'id','asc',$custcontact3);
my $t_b = threads->create(\&_fetch_intervals_worker,$delay,'id','desc',$custcontact3);
@ -989,7 +989,7 @@ if (_get_allow_fake_client_time() && $enable_profile_packages) {
_create_customers_threaded(3,2,$package,$custcontact4);
my $t1 = time;
my $delay = 15.0; #15.0; #10.0; #2.0;
my $delay = 20.0; #15.0; #10.0; #2.0;
my $t_a = threads->create(\&_fetch_preferences_worker,$delay,'id','asc',$custcontact4);
my $t_b = threads->create(\&_fetch_preferences_worker,$delay,'id','desc',$custcontact4);
my $t_c = threads->create(\&_fetch_preferences_worker,$delay,'id','desc',$custcontact9);
@ -1076,7 +1076,7 @@ if (_get_allow_fake_client_time() && $enable_profile_packages) {
_create_customers_threaded(3,2,$package,$custcontact5);
my $t1 = time;
my $delay = 15.0; #15.0; #10.0; #2.0;
my $delay = 20.0; #15.0; #10.0; #2.0;
my $t_a = threads->create(\&_fetch_subscribers_worker,$delay,'id','asc',$custcontact5);
my $t_b = threads->create(\&_fetch_subscribers_worker,$delay,'id','desc',$custcontact5);
my $t_c = threads->create(\&_fetch_subscribers_worker,$delay,'id','desc',$custcontact9);

Loading…
Cancel
Save