tax engine refactoring for Avalara and Billsoft tax vendors, #25718
[freeside.git] / FS / FS / Cron / tax_batch.pm
1 package FS::Cron::tax_batch;
2
3 use FS::TaxEngine;
4 use FS::queue;
5 use base qw( Exporter );
6 @EXPORT_OK = 'process_tax_batch';
7
8 sub process_tax_batch {
9   my %opt = @_;
10   my $engine = FS::TaxEngine->new;
11   return unless $engine->info->{batch};
12   if ( $opt{'m'} ) {
13     # then there may be queued_bill jobs running; wait for them to finish
14     while(1) {
15       my $num_jobs =
16         FS::queue->count("job = 'FS::cust_main::queued_bill' AND ".
17                          "status != 'failed'");
18       last if $num_jobs == 0;
19       warn "Waiting for billing jobs to finish ($num_jobs still active)...\n";
20       sleep(30);
21     }
22   }
23   $engine->transfer_batch(%opt);
24 }
25
26 1;