From: ivan Date: Fri, 17 Apr 2009 19:50:21 +0000 (+0000) Subject: add priority to job queue so billing jobs don't don't drown out provisioning jobs X-Git-Tag: freeside_1_7_4rc1~59 X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=83cf53bba06bd40c34e547f2ae18cd4a59109ff7;p=freeside.git add priority to job queue so billing jobs don't don't drown out provisioning jobs --- diff --git a/FS/FS/Cron/bill.pm b/FS/FS/Cron/bill.pm index 8c0f8351c..ecc891003 100644 --- a/FS/FS/Cron/bill.pm +++ b/FS/FS/Cron/bill.pm @@ -124,8 +124,8 @@ END #add job to queue that calls bill_and_collect with options my $queue = new FS::queue { - 'job' => 'FS::cust_main::queued_bill', - 'secure' => 'Y', + 'job' => 'FS::cust_main::queued_bill', + 'priority' => 99, #don't get in the way of provisioning jobs }; my $error = $queue->insert( 'custnum'=>$custnum, %args ); diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 1ab37af45..f1692b552 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -1184,6 +1184,8 @@ sub tables_hashref { 'status', 'varchar', '', $char_d, '', '', 'statustext', 'text', 'NULL', '', '', '', 'svcnum', 'int', 'NULL', '', '', '', + 'custnum', 'int', 'NULL', '', '', '', + 'priority', 'int', 'NULL', '', '', '', ], 'primary_key' => 'jobnum', 'unique' => [], diff --git a/FS/bin/freeside-queued b/FS/bin/freeside-queued index 93d735d1a..4093e5aa8 100644 --- a/FS/bin/freeside-queued +++ b/FS/bin/freeside-queued @@ -89,14 +89,19 @@ while (1) { 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 { + #anything with a priority goes after stuff without one + my $order_by = ' ORDER BY COALESCE(priority,0) ASC, jobnum ASC '; + + $order_by .= ( 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;