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

index 8c0f835..ecc8910 100644 (file)
@@ -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 );
 
index 1ab37af..f1692b5 100644 (file)
@@ -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'      => [],
index 93d735d..4093e5a 100644 (file)
@@ -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;