[freeside-commits] freeside/FS/bin freeside-cdrd,1.2,1.3

Ivan,,, ivan at wavetail.420.am
Sun Dec 21 10:09:57 PST 2008


Update of /home/cvs/cvsroot/freeside/FS/bin
In directory wavetail.420.am:/tmp/cvs-serv2210/FS/bin

Modified Files:
	freeside-cdrd 
Log Message:
have freeside-queued put billing jobs in the queue, so they run in their own short-lived processes, RT#4423

Index: freeside-cdrd
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/bin/freeside-cdrd,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- freeside-cdrd	1 Nov 2008 22:12:58 -0000	1.2
+++ freeside-cdrd	21 Dec 2008 18:09:55 -0000	1.3
@@ -2,10 +2,11 @@
 
 use strict;
 use FS::Daemon ':all'; #daemonize1 drop_root daemonize2 myexit logfile sig*
-use FS::UID qw(adminsuidsetup);
-use FS::Record qw(qsearch ); #qsearchs);
+use FS::UID qw( adminsuidsetup );
+use FS::Record qw( qsearch ); #qsearchs);
 #use FS::cdr;
 use FS::cust_pkg;
+use FS::queue;
 
 my $user = shift or die &usage;
 
@@ -51,8 +52,16 @@
                                        || svc_phone.phonenum
                             )
                   )
-    ) 
+    )
+    AND 0 = (
+      SELECT COUNT(*) FROM queue
+        WHERE job = 'FS::cust_main::queued_bill'
+          AND job.custnum = cust_pkg.custnum
+    )
+    
   ";
+# don't repeatedly queue failures
+#          AND status != 'failed'
 
 while (1) {
 
@@ -71,10 +80,17 @@
 
     #my $work_cust_pkg = $cust_pkg;
 
-    my $cust_main = $cust_pkg->cust_main;
+    #my $cust_main = $cust_pkg->cust_main;
 
     my $time = time;
-    $cust_main->bill_and_collect( 
+
+    my $job = new FS::queue {
+      'job'     => 'FS::cust_main::queued_bill',
+      'secure'  => 'Y',
+      'custnum' => $cust_pkg->custnum,
+    };
+    my $error = $job->insert(
+      'custnum'      => $cust_pkg->custnum, 
       'time'         => $time,
       'invoice_time' => $time,
       'actual_time'  => $time,
@@ -82,6 +98,13 @@
       #'debug'        => 1,
     );
 
+    if ( $error ) {
+      #die "FATAL: error inserting billing job: $error\n";
+      warn "WARNING: error inserting billing job (will retry in 30 seconds):".
+           " $error\n";
+      sleep 30; #i dunno, wait and see if the database comes back?
+    }
+
   }
 
   myexit() if sigterm() || sigint();
@@ -114,21 +137,21 @@
 }
 
 sub usage { 
-  die "Usage:\n\n  freeside-prepaidd user\n";
+  die "Usage:\n\n  freeside-cdrd user\n";
 }
 
 =head1 NAME
 
-freeside-prepaidd - Real-time daemon for prepaid packages
+freeside-cdrd - Real-time daemon for CDRs
 
 =head1 SYNOPSIS
 
-  freeside-prepaidd
+  freeside-cdrd
 
 =head1 DESCRIPTION
 
-Runs continuously and suspends or cancels any prepaid customer packages which
-have passed their renewal date (next bill date).
+Runs continuously, searches for CDRs and bills customers who have VoIP
+price plands with the B<bill_every_call> option set.
 
 =head1 SEE ALSO
 



More information about the freeside-commits mailing list