From: ivan Date: Sun, 25 Jan 2009 20:43:14 +0000 (+0000) Subject: reduce waiting time for -cdrd and -queued, RT#4667 X-Git-Tag: root_of_webpay_support~107 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=ca9154e5112d1f564c217fb958b3b979013b5967 reduce waiting time for -cdrd and -queued, RT#4667 --- diff --git a/FS/bin/freeside-cdrd b/FS/bin/freeside-cdrd index 36ff2bb4b..2cf75f31c 100644 --- a/FS/bin/freeside-cdrd +++ b/FS/bin/freeside-cdrd @@ -108,7 +108,7 @@ while (1) { } myexit() if sigterm() || sigint(); - sleep 5; # unless $found; + sleep 1 unless $found; } diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 815def49d..d4f09c18d 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -81,22 +81,19 @@ while (1) { # local $FS::UID::AutoCommit = 0; $FS::UID::AutoCommit = 0; - #assuming mysql 4.1 w/subqueries now - #my $nodepend = driver_name eq 'mysql' - # ? '' - # : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. - # ' WHERE queue_depend.jobnum = queue.jobnum ) '; my $nodepend = 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. - ' WHERE queue_depend.jobnum = queue.jobnum ) '; - - my $job = qsearchs( - 'queue', - { 'status' => 'new' }, - '', - driver_name eq 'mysql' - ? "$nodepend ORDER BY jobnum LIMIT 1 FOR UPDATE" - : "$nodepend ORDER BY jobnum FOR UPDATE LIMIT 1" - ) or do { + ' WHERE queue_depend.jobnum = queue.jobnum )'; + + my $order_by = "ORDER BY jobnum ". ( driver_name eq 'mysql' + ? 'LIMIT 1 FOR UPDATE' + : 'FOR UPDATE LIMIT 1' ); + + my $job = qsearchs({ + 'table' => 'queue', + 'hashref' => { 'status' => 'new' }, + 'extra_sql' => $nodepend, + 'order_by' => $order_by, + }) or do { # if $oldAutoCommit { dbh->commit or do { warn "WARNING: database error, closing connection: ". dbh->errstr; @@ -104,18 +101,10 @@ while (1) { next; }; # } - sleep 5; #connecting to db is expensive + sleep 1; next; }; - #assuming mysql 4.1 w/subqueries now - #if ( driver_name eq 'mysql' - # && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { - # dbh->commit or die dbh->errstr; #if $oldAutoCommit; - # sleep 5; #would be better if mysql could do everything in query above - # next; - #} - my %hash = $job->hash; $hash{'status'} = 'locked'; my $ljob = new FS::queue ( \%hash );