[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 898f4c195a8d46d4bc37a47e4d5947981723dec7

Mark Wells mark at 420.am
Tue Nov 27 19:26:12 PST 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  898f4c195a8d46d4bc37a47e4d5947981723dec7 (commit)
      from  14bf74b659b6b9b2483f66ea9876e33211b97e85 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 898f4c195a8d46d4bc37a47e4d5947981723dec7
Author: Mark Wells <mark at freeside.biz>
Date:   Tue Nov 27 19:25:25 2012 -0800

    fixes for spool_upload in multiprocess mode, #6802, #18333

diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 7a3a10b..d4f10fd 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 c266797..dfdacf0 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 756b699..f136c39 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+)::/
          )
       {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Conf.pm          |    6 +++---
 FS/FS/Cron/upload.pm   |   40 +++++++++++++++++++++++-----------------
 FS/bin/freeside-queued |    2 +-
 3 files changed, 27 insertions(+), 21 deletions(-)




More information about the freeside-commits mailing list