diff options
author | ivan <ivan> | 2009-01-25 20:43:14 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-01-25 20:43:14 +0000 |
commit | ca9154e5112d1f564c217fb958b3b979013b5967 (patch) | |
tree | df0c3ce19d438eeffc0063be2d2200b555558c7a /FS/bin/freeside-queued | |
parent | 7d154154ef1f5f2225ebf7802974f6d0bdcddc06 (diff) |
reduce waiting time for -cdrd and -queued, RT#4667
Diffstat (limited to 'FS/bin/freeside-queued')
-rw-r--r-- | FS/bin/freeside-queued | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 815def4..d4f09c1 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 ); |