svc_hardware: better error messages for bad hw_addr when not validating as a MAC...
[freeside.git] / FS / FS / Cron / export_batch.pm
1 package FS::Cron::export_batch;
2
3 use strict;
4 use vars qw( @ISA @EXPORT_OK $me $DEBUG );
5 use Exporter;
6 use FS::UID qw(dbh);
7 use FS::Record qw( qsearch qsearchs );
8 use FS::Conf;
9 use FS::export_batch;
10
11 @ISA = qw( Exporter );
12 @EXPORT_OK = qw ( export_batch_submit );
13 $DEBUG = 0;
14 $me = '[FS::Cron::export_batch]';
15
16 #freeside-daily %opt:
17 #  -v: enable debugging
18 #  -l: debugging level
19 #  -m: Experimental multi-process mode uses the job queue for multi-process and/or multi-machine billing.
20 #  -r: Multi-process mode dry run option
21 #  -a: Only process customers with the specified agentnum
22
23 sub export_batch_submit {
24   my %opt = @_;
25   local $DEBUG = ($opt{l} || 1) if $opt{v};
26   
27   warn "$me batch_submit\n" if $DEBUG;
28
29   # like pay_batch, none of this is per-agent
30   if ( $opt{a} ) {
31     warn "Export batch processing skipped in per-agent mode.\n" if $DEBUG;
32     return;
33   }
34   my @batches = qsearch({
35       table     => 'export_batch',
36       extra_sql => "WHERE status IN ('open', 'closed')",
37   });
38
39   foreach my $batch (@batches) {
40     my $export = $batch->part_export;
41     next if $export->disabled;
42     warn "processing batchnum ".$batch->batchnum.
43          " via ".$export->exporttype.  "\n"
44       if $DEBUG;
45     local $@;
46     eval {
47       $export->process($batch);
48     };
49     if ($@) {
50       dbh->rollback;
51       warn "export batch ".$batch->batchnum." failed: $@\n";
52       $batch->set(status => 'failed');
53       $batch->set(statustext => $@);
54       my $error = $batch->replace;
55       die "error recording batch status: $error"
56         if $error;
57       dbh->commit;
58     }
59   }
60 }
61
62 # currently there's no batch_receive() or anything of that sort
63
64 1;