#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 );
'status', 'varchar', '', $char_d, '', '',
'statustext', 'text', 'NULL', '', '', '',
'svcnum', 'int', 'NULL', '', '', '',
+ 'custnum', 'int', 'NULL', '', '', '',
+ 'priority', 'int', 'NULL', '', '', '',
],
'primary_key' => 'jobnum',
'unique' => [],
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;