X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-queued;h=846055dc3f75ad5041b4fed20c30aebac41bbbd1;hp=67e5e2bca18c6ca55bd4fe9a12019c5b01ce9cbf;hb=a930f5bc47c9c2de989074f1570beaa8f116bd22;hpb=251c436ab3d9b79d74ab4fc9af05aac4acf26489 diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 67e5e2bca..846055dc3 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -61,44 +61,48 @@ while (1) { } $warnkids=0; - my $nodepend = driver name eq 'mysql' + my $nodepend = driver_name eq 'mysql' ? '' : 'AND 0 = ( SELECT COUNT(*) FROM queue_depend'. ' WHERE queue_depend.jobnum = queue.jobnum ) '; - my($job, $ljob); - { - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - my $dbh = dbh; + #my($job, $ljob); + #{ + # my $oldAutoCommit = $FS::UID::AutoCommit; + # local $FS::UID::AutoCommit = 0; + $FS::UID::AutoCommit = 0; + my $dbh = dbh; - $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 { - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - sleep 5; #connecting to db is expensive - next; - }; - - if ( driver_name eq 'mysql' - && qsearch('queue_depend', { 'jobnum' => $job->jobnum } ) ) { - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - next; - } + 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 { + $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; + sleep 5; #connecting to db is expensive + next; + }; - my %hash = $job->hash; - $hash{'status'} = 'locked'; - $ljob = new FS::queue ( \%hash ); - my $error = $ljob->replace($job); - die $error if $error; + 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 ); + my $error = $ljob->replace($job); + die $error if $error; + + $dbh->commit or die $dbh->errstr; #if $oldAutoCommit; - $dbh->commit or die $dbh->errstr if $oldAutoCommit; - } + $FS::UID::AutoCommit = 1; + #} my @args = $ljob->args;