From c6da895a2fb2c233716381b7e45ebbeb1c2f6aaa Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 26 Mar 2002 00:32:46 +0000 Subject: [PATCH] further export bugfixing add 10 kid limit to freeside-queued sqlradius_reset now works (closes: Bug#372) --- FS/FS/part_export.pm | 8 +++++++- FS/bin/freeside-queued | 28 +++++++++++++++++++++------- bin/sqlradius_reset | 15 +++++++-------- httemplate/edit/part_export.cgi | 2 +- 4 files changed, 36 insertions(+), 17 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; diff --git a/bin/sqlradius_reset b/bin/sqlradius_reset index fe31d67f9..501685449 100644 --- a/bin/sqlradius_reset +++ b/bin/sqlradius_reset @@ -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; } } diff --git a/httemplate/edit/part_export.cgi b/httemplate/edit/part_export.cgi index 3d867f50a..25e8f5be0 100644 --- a/httemplate/edit/part_export.cgi +++ b/httemplate/edit/part_export.cgi @@ -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', -- 2.11.0