diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/CDR.pm b/lib/NGCP/BulkProcessor/Projects/Export/Ama/CDR.pm index 9f7fe7a..987c026 100644 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/CDR.pm +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/CDR.pm @@ -16,6 +16,7 @@ use NGCP::BulkProcessor::Projects::Export::Ama::Settings qw( $export_cdr_conditions $export_cdr_limit $export_cdr_stream + $export_cdr_rollover_fsn ); use NGCP::BulkProcessor::Logging qw ( @@ -491,13 +492,45 @@ sub _export_cdrs_create_context { _error($context,"cannot get last file sequence number"); $result = 0; } else { + my $reset = 0; if ($fsn < 0) { $fsn = 0; + $reset = 1; } elsif ($fsn >= $NGCP::BulkProcessor::Projects::Export::Ama::Format::Fields::FileSequenceNumber::max_fsn) { - _warn($context,"file sequence number $fsn exceeding limit (" . $NGCP::BulkProcessor::Projects::Export::Ama::Format::Fields::FileSequenceNumber::max_fsn . ")"); - $result = 0; + if ($export_cdr_rollover_fsn) { + $fsn = 0; + $reset = 1; + } else { + _warn($context,"file sequence number $fsn exceeding limit (" . $NGCP::BulkProcessor::Projects::Export::Ama::Format::Fields::FileSequenceNumber::max_fsn . ")"); + $result = 0; + } + } else { + _info($context,"last file sequence number is $fsn"); + } + if ($reset) { + eval { + NGCP::BulkProcessor::Dao::Trunk::accounting::mark::cleanup_system_marks(undef, + $export_cdr_stream, + ); + NGCP::BulkProcessor::Dao::Trunk::accounting::mark::set_system_mark(undef, + $export_cdr_stream, + '0' #$NGCP::BulkProcessor::Projects::Export::Ama::Format::Fields::FileSequenceNumber::min_fsn + ); + $fsn = NGCP::BulkProcessor::Dao::Trunk::accounting::mark::get_system_mark(undef, + $export_cdr_stream + ); #load mark... + }; + if ($@) { + if ($skip_errors) { + _warn($context,"problem with file sequence number reset: " . $@); + } else { + _error($context,"problem with file sequence number reset: " . $@); + } + $result = 0; + } else { + _info($context,"file sequence number reset to $fsn") + } } - _info($context,"last file sequence number is $fsn"); lock $file_sequence_number; $file_sequence_number = $fsn; } diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Settings.pm b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Settings.pm index ae07a6d..a3424e8 100644 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Settings.pm +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Settings.pm @@ -27,7 +27,7 @@ use NGCP::BulkProcessor::LoadConfig qw( split_tuple parse_regexp ); -use NGCP::BulkProcessor::Utils qw(prompt timestampdigits); +use NGCP::BulkProcessor::Utils qw(prompt timestampdigits stringtobool); #format_number check_ipnet require Exporter; @@ -52,6 +52,7 @@ our @EXPORT_OK = qw( $export_cdr_conditions $export_cdr_limit $export_cdr_stream + $export_cdr_rollover_fsn $domestic_destination_pattern $international_destination_pattern @@ -81,6 +82,7 @@ our $export_cdr_joins = []; our $export_cdr_conditions = []; our $export_cdr_limit = undef; our $export_cdr_stream = undef; +our $export_cdr_rollover_fsn = 0; our $domestic_destination_pattern = undef; our $international_destination_pattern = undef; @@ -123,6 +125,7 @@ sub update_settings { $export_cdr_limit = $data->{export_cdr_limit} if exists $data->{export_cdr_limit}; $export_cdr_stream = $data->{export_cdr_stream} if exists $data->{export_cdr_stream}; + $export_cdr_rollover_fsn = stringtobool($data->{export_cdr_rollover_fsn}) if exists $data->{export_cdr_rollover_fsn}; #if ((confval("MAINTENANCE") // 'no') eq 'yes') { # exit(0); diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.cfg b/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.cfg index e9c37c4..186a977 100755 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.cfg +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.cfg @@ -7,5 +7,6 @@ export_cdr_joins = { 'billing.voip_subscribers source_voip_subscribers' => { 'so export_cdr_conditions = { 'accounting.cdr.export_status' => { '=' => '"unexported"' } }, { 'accounting.cdr.call_status' => { '=' => '"ok"' } }, { 'accounting.cdr.rating_status' => { '=' => '"ok"' } } export_cdr_limit = 300000 export_cdr_stream = ama_simple +export_cdr_rollover_fsn = 1 ama_filename_format = %1$s%2$03d.debug.ama diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.debug.cfg b/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.debug.cfg index 9b374a4..e815f82 100755 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.debug.cfg +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/settings.debug.cfg @@ -11,5 +11,6 @@ export_cdr_stream = ama_simple #default #export_cdr_limit = 3500 #300000 +export_cdr_rollover_fsn = 1 ama_filename_format = %1$s%2$03d.debug.ama