diff options
author | ivan <ivan> | 2009-04-25 22:50:37 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-04-25 22:50:37 +0000 |
commit | 0d4f3972712426eb537aa6eb1db3c8cfac82fdb7 (patch) | |
tree | b34876c836a82dc02c88953541afeaef79ab6680 | |
parent | c5b1888828acf880864aaba351e07f1c767ad841 (diff) |
add dry run to multi-process mode for testing, RT#4412
-rw-r--r-- | FS/FS/Cron/bill.pm | 86 | ||||
-rwxr-xr-x | FS/bin/freeside-daily | 6 |
2 files changed, 50 insertions, 42 deletions
diff --git a/FS/FS/Cron/bill.pm b/FS/FS/Cron/bill.pm index f06fc1532..e6d593004 100644 --- a/FS/FS/Cron/bill.pm +++ b/FS/FS/Cron/bill.pm @@ -50,44 +50,46 @@ sub bill { # select * from cust_main where my $where_pkg = <<"END"; - 0 < ( select count(*) from cust_pkg - where cust_main.custnum = cust_pkg.custnum - and ( cancel is null or cancel = 0 ) - and ( setup is null or setup = 0 - or bill is null or bill <= $time - or ( expire is not null and expire <= $^T ) - or ( adjourn is not null and adjourn <= $^T ) - ) - ) + EXISTS( SELECT 1 FROM cust_pkg + WHERE cust_main.custnum = cust_pkg.custnum + AND ( cancel IS NULL OR cancel = 0 ) + AND ( setup IS NULL OR setup = 0 + OR bill IS NULL OR bill <= $time + OR ( expire IS NOT NULL AND expire <= $^T ) + OR ( adjourn IS NOT NULL AND adjourn <= $^T ) + ) + ) END # or my $where_bill_event = <<"END"; - 0 < ( select count(*) from cust_bill - where cust_main.custnum = cust_bill.custnum - and 0 < charged - - coalesce( - ( select sum(amount) from cust_bill_pay - where cust_bill.invnum = cust_bill_pay.invnum ) - ,0 - ) - - coalesce( - ( select sum(amount) from cust_credit_bill - where cust_bill.invnum = cust_credit_bill.invnum ) - ,0 - ) - and 0 < ( select count(*) from part_bill_event - where payby = cust_main.payby - and ( disabled is null or disabled = '' ) - and seconds <= $time - cust_bill._date - and 0 = ( select count(*) from cust_bill_event - where cust_bill.invnum = cust_bill_event.invnum - and part_bill_event.eventpart = cust_bill_event.eventpart - and status = 'done' - ) - - ) - ) + EXISTS( + SELECT 1 FROM cust_bill + WHERE cust_main.custnum = cust_bill.custnum + AND 0 < charged + - COALESCE( + ( SELECT SUM(amount) FROM cust_bill_pay + WHERE cust_bill.invnum = cust_bill_pay.invnum + ),0 + ) + - COALESCE( + ( SELECT SUM(amount) FROM cust_credit_bill + WHERE cust_bill.invnum = cust_credit_bill.invnum + ),0 + ) + AND EXISTS( + SELECT 1 FROM part_bill_event + WHERE payby = cust_main.payby + AND ( disabled is null or disabled = '' ) + AND seconds <= $time - cust_bill._date + AND NOT EXISTS ( + SELECT 1 FROM cust_bill_event + WHERE cust_bill.invnum = cust_bill_event.invnum + AND part_bill_event.eventpart = cust_bill_event.eventpart + AND status = 'done' + ) + ) + ) END push @search, "( $where_pkg OR $where_bill_event )"; @@ -133,12 +135,16 @@ END if ( $opt{'m'} ) { - #add job to queue that calls bill_and_collect with options - my $queue = new FS::queue { - 'job' => 'FS::cust_main::queued_bill', - 'priority' => 99, #don't get in the way of provisioning jobs - }; - my $error = $queue->insert( 'custnum'=>$custnum, %args ); + if ( $opt{'r'} ) { + warn "DRY RUN: would add custnum $custnum for queued_bill\n"; + } else { + #add job to queue that calls bill_and_collect with options + my $queue = new FS::queue { + 'job' => 'FS::cust_main::queued_bill', + 'priority' => 99, #don't get in the way of provisioning jobs + }; + my $error = $queue->insert( 'custnum'=>$custnum, %args ); + } } else { diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index d76cb37b9..cbcbc42fe 100755 --- a/FS/bin/freeside-daily +++ b/FS/bin/freeside-daily @@ -6,7 +6,7 @@ use FS::UID qw(adminsuidsetup); &untaint_argv; #what it sounds like (eww) use vars qw(%opt); -getopts("p:a:d:vl:sy:nmk", \%opt); +getopts("p:a:d:vl:sy:nmrk", \%opt); my $user = shift or die &usage; adminsuidsetup $user; @@ -57,7 +57,7 @@ freeside-daily - Run daily billing and invoice collection events. =head1 SYNOPSIS - freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] [ -l level ] [ -m ] [ -k ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] [ -l level ] [ -m ] [ -r ] [ -k ] user [ custnum custnum ... ] =head1 DESCRIPTION @@ -91,6 +91,8 @@ the bill and collect methods of a cust_main object. See L<FS::cust_main>. -m: Experimental multi-process mode uses the job queue for multi-process and/or multi-machine billing. + -r: Multi-process mode dry run option + -k: skip notify_flat_delay and vacuum user: From the mapsecrets file - see config.html from the base documentation |