further export bugfixing
authorivan <ivan>
Tue, 26 Mar 2002 00:32:46 +0000 (00:32 +0000)
committerivan <ivan>
Tue, 26 Mar 2002 00:32:46 +0000 (00:32 +0000)
add 10 kid limit to freeside-queued
sqlradius_reset now works (closes: Bug#372)

FS/FS/part_export.pm
FS/bin/freeside-queued
bin/sqlradius_reset
httemplate/edit/part_export.cgi

index eabcede..41dfe77 100644 (file)
@@ -409,6 +409,8 @@ package FS::part_export::infostreet;
 use vars qw(@ISA);
 @ISA = qw(FS::part_export);
 
+sub rebless { shift; }
+
 sub _export_insert {
   my( $self, $svc_acct ) = (shift, shift);
   $self->infostreet_queue( $svc_acct->svcnum,
@@ -488,6 +490,8 @@ package FS::part_export::sqlradius;
 use vars qw(@ISA);
 @ISA = qw(FS::part_export);
 
+sub rebless { shift; }
+
 sub _export_insert {
   my($self, $svc_acct) = (shift, shift);
 
@@ -684,7 +688,9 @@ sub sqlradius_connect {
   package FS::part_export::myexport;
   use vars qw(@ISA);
   @ISA = qw(FS::part_export);
-  
+
+  sub rebless { shift; }
+
   sub _export_insert {
     my($self, $svc_something) = (shift, shift);
     $self->myexport_queue( $svc_acct->svcnum, 'insert',
index fff77f0..f6226cc 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 
 use strict;
-use vars qw( $log_file $sigterm $sigint );
+use vars qw( $log_file $sigterm $sigint $kids $max_kids );
 use subs qw( _die _logmsg );
 use Fcntl qw(:flock);
 use POSIX qw(setsid);
@@ -19,15 +19,18 @@ use FS::part_export;
 
 my $pid_file = '/var/run/freeside-queued.pid';
 
+$max_kids = '10'; #guess it should be a config file...
+$kids = 0;
+
 my $user = shift or die &usage;
 
 &daemonize1;
 
-sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; }
+sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; $kids--; }
 $SIG{CHLD} =  \&REAPER;
 
- $sigterm = 0;
- $sigint = 0;
+$sigterm = 0;
+$sigint = 0;
 $SIG{INT} = sub { warn "SIGINT received; shutting down\n"; $sigint++; };
 $SIG{TERM} = sub { warn "SIGTERM received; shutting down\n"; $sigterm++; };
 
@@ -45,8 +48,17 @@ $SIG{__WARN__} = \&_logmsg;
 
 warn "freeside-queued starting\n";
 
+my $warnkids=0;
 while (1) {
 
+  #prevent runaway forking
+  if ( $kids >= $max_kids ) {
+    warn "WARNING: maximum $kids children reached\n" unless $warnkids++;
+    sleep 1; #waiting for signals is cheap
+    next;
+  }
+  $warnkids=0;
+
   my $job = qsearchs(
     'queue',
     { 'status' => 'new' },
@@ -55,7 +67,7 @@ while (1) {
       ? 'ORDER BY jobnum LIMIT 1 FOR UPDATE'
       : 'ORDER BY jobnum FOR UPDATE LIMIT 1'
   ) or do {
-    sleep 5;
+    sleep 5; #connecting to db is expensive
     next;
   };
 
@@ -67,7 +79,6 @@ while (1) {
 
   my @args = $ljob->args;
 
-  # number of children limit?
   defined( my $pid = fork ) or do {
     warn "WARNING: can't fork: $!\n";
     my %hash = $job->hash;
@@ -76,9 +87,12 @@ while (1) {
     my $ljob = new FS::queue ( \%hash );
     my $error = $ljob->replace($job);
     die $error if $error;
+    next; #don't increment the kid counter
   };
 
-  unless ( $pid ) { #kid time
+  if ( $pid ) {
+    $kids++;
+  } else { #kid time
 
     #get new db handles
     $FS::UID::dbh->{InactiveDestroy} = 1;
index fe31d67..5016854 100644 (file)
@@ -2,7 +2,10 @@
 
 use strict;
 use FS::UID qw(adminsuidsetup);
+use FS::Record qw(qsearch qsearchs);
 use FS::part_export;
+use FS::svc_acct;
+use FS::cust_svc;
 
 my $user = shift or die &usage;
 adminsuidsetup $user;
@@ -23,17 +26,13 @@ foreach my $export ( @exports ) {
 
 foreach my $export ( @exports ) {
   my @svc_acct =
-    map { qsearchs{'svc_acct', { 'svcnum' => $_->svcnum } ) }
+    map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
       qsearch('cust_svc', { 'svcpart' => $export->part_svc->svcpart } );
   foreach my $svc_acct ( @svc_acct ) {
 
-    #flase laziness with FS::svc_acct::insert (like it matters)
-    my $error = $part_export->export_insert($self);
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return "exporting to ". $part_export->exporttype.
-             " (transaction rolled back): $error";
-    }
+    #false laziness with FS::svc_acct::insert (like it matters)
+    my $error = $export->export_insert($svc_acct);
+    die $error if $error;
 
   }
 }
index 3d867f5..25e8f5b 100644 (file)
@@ -70,7 +70,7 @@ my %exports = (
         'password' => { label=>'Database password' },
       },
       'nodomain' => 'Y',
-      'notes' => 'Not specifying datasrc will export to the freeside database? (no...  notes on MySQL replication, DBI::Proxy, etc., from Conf.pm && export.html etc.',
+      'notes' => 'Not specifying datasrc will export to the freeside database? (no...  notes on MySQL replication, DBI::Proxy, etc., from Conf.pm && export.html etc., reset with bin/sqlradius_reset',
     },
     'cyrus' => {
       'desc' => 'Real-time export to Cyrus IMAP server',