summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2002-03-26 00:32:46 +0000
committerivan <ivan>2002-03-26 00:32:46 +0000
commitc6da895a2fb2c233716381b7e45ebbeb1c2f6aaa (patch)
tree2ccff8ded5a939ecdb06d72ae1df0e737af3accc /FS
parent79580638b7adc429cc57fc434d83f53e34df018d (diff)
further export bugfixing
add 10 kid limit to freeside-queued sqlradius_reset now works (closes: Bug#372)
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/part_export.pm8
-rw-r--r--FS/bin/freeside-queued28
2 files changed, 28 insertions, 8 deletions
diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm
index eabcedec1..41dfe77a1 100644
--- a/FS/FS/part_export.pm
+++ b/FS/FS/part_export.pm
@@ -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',
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued
index fff77f01b..f6226cca1 100644
--- a/FS/bin/freeside-queued
+++ b/FS/bin/freeside-queued
@@ -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;