diff options
author | Mark Wells <mark@freeside.biz> | 2014-06-26 15:47:22 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2014-06-26 16:04:51 -0700 |
commit | fa978560e3b0473728ebf2fb32625765465c230a (patch) | |
tree | 07f90f1a1980f0f1fee00ad736a4b1adb5ca723e /FS/FS/Cron | |
parent | 3e3441036353ea99dc85548bbdbe810edc81b181 (diff) |
NENA2 E911 export and batch-oriented exports in general, #14049
Diffstat (limited to 'FS/FS/Cron')
-rw-r--r-- | FS/FS/Cron/export_batch.pm | 64 | ||||
-rw-r--r-- | FS/FS/Cron/pay_batch.pm | 6 |
2 files changed, 67 insertions, 3 deletions
diff --git a/FS/FS/Cron/export_batch.pm b/FS/FS/Cron/export_batch.pm new file mode 100644 index 0000000..cb16eee --- /dev/null +++ b/FS/FS/Cron/export_batch.pm @@ -0,0 +1,64 @@ +package FS::Cron::export_batch; + +use strict; +use vars qw( @ISA @EXPORT_OK $me $DEBUG ); +use Exporter; +use FS::UID qw(dbh); +use FS::Record qw( qsearch qsearchs ); +use FS::Conf; +use FS::export_batch; + +@ISA = qw( Exporter ); +@EXPORT_OK = qw ( export_batch_submit ); +$DEBUG = 0; +$me = '[FS::Cron::export_batch]'; + +#freeside-daily %opt: +# -v: enable debugging +# -l: debugging level +# -m: Experimental multi-process mode uses the job queue for multi-process and/or multi-machine billing. +# -r: Multi-process mode dry run option +# -a: Only process customers with the specified agentnum + +sub export_batch_submit { + my %opt = @_; + local $DEBUG = ($opt{l} || 1) if $opt{v}; + + warn "$me batch_submit\n" if $DEBUG; + + # like pay_batch, none of this is per-agent + if ( $opt{a} ) { + warn "Export batch processing skipped in per-agent mode.\n" if $DEBUG; + return; + } + my @batches = qsearch({ + table => 'export_batch', + extra_sql => "WHERE status IN ('open', 'closed')", + }); + + foreach my $batch (@batches) { + my $export = $batch->part_export; + next if $export->disabled; + warn "processing batchnum ".$batch->batchnum. + " via ".$export->exporttype. "\n" + if $DEBUG; + local $@; + eval { + $export->process($batch); + }; + if ($@) { + dbh->rollback; + warn "export batch ".$batch->batchnum." failed: $@\n"; + $batch->set(status => 'failed'); + $batch->set(statustext => $@); + my $error = $batch->replace; + die "error recording batch status: $error" + if $error; + dbh->commit; + } + } +} + +# currently there's no batch_receive() or anything of that sort + +1; diff --git a/FS/FS/Cron/pay_batch.pm b/FS/FS/Cron/pay_batch.pm index 0ab37dd..432271d 100644 --- a/FS/FS/Cron/pay_batch.pm +++ b/FS/FS/Cron/pay_batch.pm @@ -11,7 +11,7 @@ use FS::queue; use FS::agent; @ISA = qw( Exporter ); -@EXPORT_OK = qw ( batch_submit batch_receive ); +@EXPORT_OK = qw ( pay_batch_submit pay_batch_receive ); $DEBUG = 0; $me = '[FS::Cron::pay_batch]'; @@ -22,7 +22,7 @@ $me = '[FS::Cron::pay_batch]'; # -r: Multi-process mode dry run option # -a: Only process customers with the specified agentnum -sub batch_submit { +sub pay_batch_submit { my %opt = @_; local $DEBUG = ($opt{l} || 1) if $opt{v}; # if anything goes wrong, don't try to roll back previously submitted batches @@ -71,7 +71,7 @@ sub batch_submit { 1; } -sub batch_receive { +sub pay_batch_receive { my %opt = @_; local $DEBUG = ($opt{l} || 1) if $opt{v}; local $FS::UID::AutoCommit = 0; |