add priority to job queue so billing jobs don't don't drown out provisioning jobs
authorivan <ivan>
Fri, 17 Apr 2009 19:50:11 +0000 (19:50 +0000)
committerivan <ivan>
Fri, 17 Apr 2009 19:50:11 +0000 (19:50 +0000)
FS/FS/Cron/bill.pm
FS/FS/Schema.pm
FS/bin/freeside-queued

index 6334056..2e432cd 100644 (file)
@@ -129,8 +129,9 @@ END
 
       #add job to queue that calls bill_and_collect with options
       my $queue = new FS::queue {
 
       #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',
+        'secure'   => 'Y',
+        'priority' => 99, #don't get in the way of provisioning jobs
       };
       my $error = $queue->insert( 'custnum'=>$custnum, %args );
 
       };
       my $error = $queue->insert( 'custnum'=>$custnum, %args );
 
index c7bbf61..66be8b6 100644 (file)
@@ -1504,6 +1504,7 @@ sub tables_hashref {
         'svcnum',         'int', 'NULL',      '', '', '', 
         'custnum',        'int', 'NULL',      '', '', '',
         'secure',        'char', 'NULL',       1, '', '',
         'svcnum',         'int', 'NULL',      '', '', '', 
         'custnum',        'int', 'NULL',      '', '', '',
         'secure',        'char', 'NULL',       1, '', '',
+        'priority',       'int', 'NULL',      '', '', '',
       ],
       'primary_key' => 'jobnum',
       'unique'      => [],
       ],
       'primary_key' => 'jobnum',
       'unique'      => [],
index d4f09c1..8c07638 100644 (file)
@@ -84,9 +84,12 @@ while (1) {
   my $nodepend = '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 $order_by = "ORDER BY jobnum ". ( driver_name eq 'mysql'
-                                         ? 'LIMIT 1 FOR UPDATE'
-                                         : 'FOR UPDATE LIMIT 1' );
+  #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',
 
   my $job = qsearchs({
     'table'     => 'queue',