MT#14317 passing now() to interval catchup and resize

formerly, the contract_balance catchup (and resize) procedures
used contracts.modified_timestamp, whose value was intended to
be set explicitly upon update operations.

it turns out that mysql ON UPDATE current_timestamp columns
effectively ignore the explicit timestamp value, unless it
exactly matches the old timestamp value.

while this is not an issue for the logic in production usage,
this seems to be the reason why the api-balance_intervals.t test
fails occassionally with its time-warp cases.

Change-Id: I504dd98548b88c99079e071598806d884c4422eb
changes/41/2441/1
Rene Krenn 10 years ago
parent 0512e767b9
commit c7b3d74a21

@ -163,7 +163,7 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$form->values->{$_.'_id'} = $form->values->{$_}{id} || undef; $form->values->{$_.'_id'} = $form->values->{$_}{id} || undef;
delete $form->values->{$_}; delete $form->values->{$_};
} }
$form->values->{modify_timestamp} = $now; $form->values->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns
my $mappings_to_create = []; my $mappings_to_create = [];
my $delete_mappings = 0; my $delete_mappings = 0;
@ -192,11 +192,13 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $contract, contract => $contract,
old_package => $old_package,); old_package => $old_package,
now => $now);
$balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c,
contract => $contract, contract => $contract,
old_package => $old_package, old_package => $old_package,
balance => $balance, balance => $balance,
now => $now,
); );
if ($is_peering_reseller && if ($is_peering_reseller &&

@ -480,7 +480,7 @@ sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) {
delete $form->values->{$_}; delete $form->values->{$_};
} }
$form->values->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES; $form->values->{profile_package_id} = undef unless NGCP::Panel::Utils::ProfilePackages::ENABLE_PROFILE_PACKAGES;
$form->values->{modify_timestamp} = $now; $form->values->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns
$form->values->{external_id} = $form->field('external_id')->value; $form->values->{external_id} = $form->field('external_id')->value;
unless($form->values->{max_subscribers} && length($form->values->{max_subscribers})) { unless($form->values->{max_subscribers} && length($form->values->{max_subscribers})) {
$form->values->{max_subscribers} = undef; $form->values->{max_subscribers} = undef;
@ -516,11 +516,13 @@ sub edit :Chained('base_restricted') :PathPart('edit') :Args(0) {
my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $contract, contract => $contract,
old_package => $old_package,); old_package => $old_package,
now => $now);
$balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c,
contract => $contract, contract => $contract,
old_package => $old_package, old_package => $old_package,
balance => $balance, balance => $balance,
now => $now,
); );
my $new_ext_id = $contract->external_id // ''; my $new_ext_id = $contract->external_id // '';

@ -170,7 +170,7 @@ sub update_contract {
}); });
delete $resource->{type}; delete $resource->{type};
$resource->{modify_timestamp} = $now; $resource->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns
if($old_resource->{contact_id} != $resource->{contact_id}) { if($old_resource->{contact_id} != $resource->{contact_id}) {
my $syscontact = $c->model('DB')->resultset('contacts') my $syscontact = $c->model('DB')->resultset('contacts')
@ -197,11 +197,13 @@ sub update_contract {
my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $contract, contract => $contract,
old_package => $old_package,); old_package => $old_package,
now => $now); #make balance_intervals.t work
$balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c,
contract => $contract, contract => $contract,
old_package => $old_package, old_package => $old_package,
balance => $balance, balance => $balance,
now => $now,
); );
if($old_resource->{status} ne $resource->{status}) { if($old_resource->{status} ne $resource->{status}) {

@ -182,7 +182,7 @@ sub update_customer {
}); });
delete $resource->{type}; delete $resource->{type};
$resource->{modify_timestamp} = $now; $resource->{modify_timestamp} = $now; #problematic for ON UPDATE current_timestamp columns
my $custcontact; my $custcontact;
if($old_resource->{contact_id} != $resource->{contact_id}) { if($old_resource->{contact_id} != $resource->{contact_id}) {
@ -263,11 +263,13 @@ sub update_customer {
my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c, my $balance = NGCP::Panel::Utils::ProfilePackages::catchup_contract_balances(c => $c,
contract => $customer, contract => $customer,
old_package => $old_package,); old_package => $old_package,
now => $now); #make balance_intervals.t work
$balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c, $balance = NGCP::Panel::Utils::ProfilePackages::resize_actual_contract_balance(c => $c,
contract => $customer, contract => $customer,
old_package => $old_package, old_package => $old_package,
balance => $balance, balance => $balance,
now => $now,
); );
if(($customer->external_id // '') ne $old_ext_id) { if(($customer->external_id // '') ne $old_ext_id) {

@ -154,7 +154,7 @@ sub catchup_contract_balances {
$now //= $contract->modify_timestamp; $now //= $contract->modify_timestamp;
$old_package = $contract->profile_package if !exists $params{old_package}; $old_package = $contract->profile_package if !exists $params{old_package};
$c->log->debug('catchup contract ' . $contract->id . ' contract_balances to now - ' . NGCP::Panel::Utils::DateTime::to_string($now)) if $c; #$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); my ($start_mode,$interval_unit,$interval_value,$carry_over_mode,$has_package,$notopup_expiration);

Loading…
Cancel
Save