[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 245fa062729d5f48da967ec91f476ca075c5ebc0

Mark Wells mark at 420.am
Mon Dec 3 12:13:44 PST 2012


The branch, FREESIDE_2_3_BRANCH has been updated
       via  245fa062729d5f48da967ec91f476ca075c5ebc0 (commit)
      from  aacc69fe90498b90126eab16d2ffe6015bcd5952 (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 245fa062729d5f48da967ec91f476ca075c5ebc0
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Dec 3 11:47:37 2012 -0800

    don't queue spool_upload jobs until all queued_bill jobs are finished, #6802

diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm
index dfdacf0..1f21ee9 100644
--- a/FS/FS/Cron/upload.pm
+++ b/FS/FS/Cron/upload.pm
@@ -112,6 +112,29 @@ sub upload {
 
   } #!if cust_bill-ftp_spool
 
+  # if there's nothing to do, don't hold up the rest of the process
+  return '' if !@tasks;
+
+  # wait for any ongoing billing jobs to complete
+  if ($opt{m}) {
+    my $dbh = dbh;
+    my $sql = "SELECT count(*) FROM queue LEFT JOIN cust_main USING(custnum) ".
+    "WHERE queue.job='FS::cust_main::queued_bill' AND status != 'failed'";
+    if (@agents) {
+      $sql .= ' AND cust_main.agentnum IN('.
+        join(',', map {$_->agentnum} @agents).
+        ')';
+    }
+    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;
+      warn "Waiting 5min for billing to complete...\n" if $DEBUG;
+      sleep 300;
+    }
+  }
+
   foreach (@tasks) {
 
     my $agentnum = $_->{agentnum};
@@ -166,21 +189,6 @@ sub spool_upload {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  # 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";

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

Summary of changes:
 FS/FS/Cron/upload.pm |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)




More information about the freeside-commits mailing list