summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2012-11-27 19:25:25 -0800
committerMark Wells <mark@freeside.biz>2012-11-27 19:25:25 -0800
commit898f4c195a8d46d4bc37a47e4d5947981723dec7 (patch)
tree95b2f3b45d2759ac7ee92f6025b0254b0d88b053
parent14bf74b659b6b9b2483f66ea9876e33211b97e85 (diff)
fixes for spool_upload in multiprocess mode, #6802, #18333
-rw-r--r--FS/FS/Conf.pm6
-rw-r--r--FS/FS/Cron/upload.pm40
-rw-r--r--FS/bin/freeside-queued2
3 files changed, 27 insertions, 21 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 7a3a10b6f..d4f10fd22 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -3099,21 +3099,21 @@ and customer address. Include units.',
{
'key' => 'cust_bill-ftpusername',
'section' => 'invoicing',
- 'description' => 'Enable FTP of raw invoice data - server.',
+ 'description' => 'Enable FTP of raw invoice data - login.',
'type' => 'text',
},
{
'key' => 'cust_bill-ftppassword',
'section' => 'invoicing',
- 'description' => 'Enable FTP of raw invoice data - server.',
+ 'description' => 'Enable FTP of raw invoice data - password.',
'type' => 'text',
},
{
'key' => 'cust_bill-ftpdir',
'section' => 'invoicing',
- 'description' => 'Enable FTP of raw invoice data - server.',
+ 'description' => 'Enable FTP of raw invoice data - path.',
'type' => 'text',
},
diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm
index c2667978d..dfdacf0d7 100644
--- a/FS/FS/Cron/upload.pm
+++ b/FS/FS/Cron/upload.pm
@@ -146,7 +146,7 @@ sub spool_upload {
my $conf = new FS::Conf;
my $dir = '%%%FREESIDE_EXPORT%%%/export.'. $FS::UID::datasrc. '/cust_bill';
- my $agentnum = $opt{agentnum} or die "no agentnum provided\n";
+ my $agentnum = $opt{agentnum} || '';
my $url = $opt{url} or die "no url for agent $agentnum\n";
$url =~ s/^\s+//; $url =~ s/\s+$//;
@@ -166,12 +166,31 @@ sub spool_upload {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
- my $agent = qsearchs( 'agent', { agentnum => $agentnum } )
- or die "no such agent: $agentnum";
- $agent->select_for_update; #mutex
+ # wait for any ongoing billing jobs to complete
+ # (should this exclude status='failed')?
+ if ($opt{m}) {
+ my $sql = "SELECT count(*) FROM queue LEFT JOIN cust_main USING(custnum) ".
+ "WHERE queue.job='FS::cust_main::queued_bill'";
+ $sql .= " AND cust_main.agentnum = $agentnum" if $agentnum =~ /^\d+$/;
+ my $sth = $dbh->prepare($sql) or die $dbh->errstr;
+ while (1) {
+ $sth->execute()
+ or die "Unexpected error executing statement $sql: ". $sth->errstr;
+ last if $sth->fetchrow_arrayref->[0] == 0;
+ sleep 300;
+ }
+ }
+
+ if ( $agentnum ) {
+ my $agent = qsearchs( 'agent', { agentnum => $agentnum } )
+ or die "no such agent: $agentnum";
+ $agent->select_for_update; #mutex
+ }
if ( $opt{'format'} eq 'billco' ) {
+ die "no agentnum provided\n" unless $agentnum;
+
my $zipfile = "$dir/agentnum$agentnum-$opt{date}.zip";
unless ( -f "$dir/agentnum$agentnum-header.csv" ||
@@ -183,19 +202,6 @@ sub spool_upload {
return;
}
- # a better way?
- if ($opt{m}) {
- my $sql = "SELECT count(*) FROM queue LEFT JOIN cust_main USING(custnum) ".
- "WHERE queue.job='FS::cust_main::queued_bill' AND cust_main.agentnum = ?";
- my $sth = $dbh->prepare($sql) or die $dbh->errstr;
- while (1) {
- $sth->execute( $agentnum )
- or die "Unexpected error executing statement $sql: ". $sth->errstr;
- last if $sth->fetchrow_arrayref->[0];
- sleep 300;
- }
- }
-
foreach ( qw ( header detail ) ) {
rename "$dir/agentnum$agentnum-$_.csv",
"$dir/agentnum$agentnum-$opt{date}-$_.csv";
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index 756b699d4..f136c3910 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -186,7 +186,7 @@ while (1) {
dbh->{'private_profile'} = {} if UNIVERSAL::can(dbh, 'sprintProfile');
#auto-use classes...
- if ( $ljob->job =~ /(FS::(part_export|cust_main|cust_pkg)::\w+)::/
+ if ( $ljob->job =~ /(FS::(part_export|cust_main|cust_pkg|Cron)::\w+)::/
|| $ljob->job =~ /(FS::\w+)::/
)
{