From e3dd31c479fb51c2a543ef3c0d7aff59bc44d6f4 Mon Sep 17 00:00:00 2001 From: jayce Date: Thu, 27 Sep 2007 18:24:33 +0000 Subject: [PATCH] Multi-System Billing: with a -m flag, daily will queue billing jobs instead of running each. freeside-queued will then pick it up, allowing multiple simultaneous jobs to run, as well as multiple machines. Also adds a 'Secure' column to the queue system, allowing for billing jobs to define themselves as 'secure only' in cases where a box might be using the encryption. This allows you to run secure only jobs (such as a collect) on boxes that can. --- FS/FS/Cron/bill.pm | 21 ++++++++++++++++----- FS/FS/Schema.pm | 1 + FS/FS/cust_main.pm | 10 ++++++++++ FS/bin/freeside-daily | 4 ++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/FS/FS/Cron/bill.pm b/FS/FS/Cron/bill.pm index 1a6c4a7f5..38fbae524 100644 --- a/FS/FS/Cron/bill.pm +++ b/FS/FS/Cron/bill.pm @@ -44,7 +44,7 @@ sub bill { ) ) END - + my $where_event = join(' OR ', map { my $eventtable = $_; @@ -76,7 +76,7 @@ END my $extra_sql = ( scalar(%search) ? ' AND ' : ' WHERE ' ). "( $where_pkg OR $where_event )"; - + my @cust_main; if ( @ARGV ) { @cust_main = map { qsearchs('cust_main', { custnum => $_, %search } ) } @ARGV @@ -95,12 +95,23 @@ END } - foreach my $cust_main ( @cust_main ) { + my($cust_main,%saw); + foreach $cust_main ( @cust_main ) { if ( $opt{'m'} ) { - die "XXX multi-process mode not yet completed"; #add job to queue that calls bill_and_collect with options + my $queue = new FS::queue { + 'job' => 'FS::cust_main::queued_bill', + 'secure' => 'Y', + }; + my $error = $queue->insert( + 'custnum' => $cust_main->custnum, + 'time' => $time, + 'invoice_time' => $invoice_time, + 'check_freq' => $check_freq, + 'resetup' => $opt{'s'} ? $opt{'s'} : 0, + ); } else { @@ -112,7 +123,7 @@ END ); } - + } } diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 3084e3625..e147e6818 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1156,6 +1156,7 @@ sub tables_hashref { 'status', 'varchar', '', $char_d, '', '', 'statustext', 'text', 'NULL', '', '', '', 'svcnum', 'int', 'NULL', '', '', '', + 'secure', 'char', 'NULL', 1, '', '', # Y = recur tax exempt ], 'primary_key' => 'jobnum', 'unique' => [], diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 6512888ca..9627f9ffd 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -5822,6 +5822,16 @@ sub _agent_plandata { } +sub queued_bill { + ## actual sub, not a method, designed to be called from the queue. + ## sets up the customer, and calls the bill_and_collect + my (%args) = @_; #, ($time, $invoice_time, $check_freq, $resetup) = @_; + my $cust_main = qsearchs( 'cust_main', { custnum => $args{'custnum'} } ); + $cust_main->bill_and_collect( + %args, + ); +} + =back =head1 BUGS diff --git a/FS/bin/freeside-daily b/FS/bin/freeside-daily index f0ec9f041..fb855b748 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:n", \%opt); +getopts("p:a:d:vl:sy:nm", \%opt); my $user = shift or die &usage; adminsuidsetup $user; @@ -55,7 +55,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 ] user [ custnum custnum ... ] + freeside-daily [ -d 'date' ] [ -y days ] [ -p 'payby' ] [ -a agentnum ] [ -s ] [ -v ] [ -l level ] [ -m ]user [ custnum custnum ... ] =head1 DESCRIPTION -- 2.11.0