2012-08-29 00:01:31 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Database-backed job queue code.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2020-01-10 00:00:51 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2017-02-24 16:17:16 +00:00
|
|
|
use Wikimedia\Rdbms\DBConnectionError;
|
|
|
|
|
use Wikimedia\Rdbms\DBError;
|
2020-01-10 00:00:51 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2019-07-06 05:43:45 +00:00
|
|
|
use Wikimedia\Rdbms\IMaintainableDatabase;
|
2023-02-23 13:59:10 +00:00
|
|
|
use Wikimedia\Rdbms\SelectQueryBuilder;
|
2016-10-12 05:36:03 +00:00
|
|
|
use Wikimedia\ScopedCallback;
|
2012-08-29 00:01:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to handle job queues stored in the DB
|
|
|
|
|
*
|
|
|
|
|
* @ingroup JobQueue
|
2012-11-06 00:43:44 +00:00
|
|
|
* @since 1.21
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
class JobQueueDB extends JobQueue {
|
2020-05-12 22:37:45 +00:00
|
|
|
private const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating
|
|
|
|
|
private const MAX_AGE_PRUNE = 604800; // integer; seconds a job can live once claimed
|
|
|
|
|
private const MAX_JOB_RANDOM = 2147483647; // integer; 2^31 - 1, used for job_random
|
|
|
|
|
private const MAX_OFFSET = 255; // integer; maximum number of rows to skip
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
/** @var IMaintainableDatabase|DBError|null */
|
2019-03-09 01:01:30 +00:00
|
|
|
protected $conn;
|
2013-03-10 08:06:02 +00:00
|
|
|
|
2019-03-09 01:01:30 +00:00
|
|
|
/** @var array|null Server configuration array */
|
|
|
|
|
protected $server;
|
|
|
|
|
/** @var string|null Name of an external DB cluster or null for the local DB cluster */
|
|
|
|
|
protected $cluster;
|
2012-12-21 01:29:02 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Additional parameters include:
|
2019-03-09 01:01:30 +00:00
|
|
|
* - server : Server configuration array for Database::factory. Overrides "cluster".
|
2012-12-21 01:29:02 +00:00
|
|
|
* - cluster : The name of an external cluster registered via LBFactory.
|
|
|
|
|
* If not specified, the primary DB cluster for the wiki will be used.
|
|
|
|
|
* This can be overridden with a custom cluster so that DB handles will
|
|
|
|
|
* be retrieved via LBFactory::getExternalLB() and getConnection().
|
2013-11-25 17:12:42 +00:00
|
|
|
* @param array $params
|
2012-12-21 01:29:02 +00:00
|
|
|
*/
|
|
|
|
|
protected function __construct( array $params ) {
|
|
|
|
|
parent::__construct( $params );
|
2013-03-10 08:06:02 +00:00
|
|
|
|
2019-03-09 01:01:30 +00:00
|
|
|
if ( isset( $params['server'] ) ) {
|
|
|
|
|
$this->server = $params['server'];
|
|
|
|
|
} elseif ( isset( $params['cluster'] ) && is_string( $params['cluster'] ) ) {
|
|
|
|
|
$this->cluster = $params['cluster'];
|
|
|
|
|
}
|
2012-12-21 01:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-08 18:20:54 +00:00
|
|
|
protected function supportedOrders() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'random', 'timestamp', 'fifo' ];
|
2013-03-03 04:41:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function optimalOrder() {
|
|
|
|
|
return 'random';
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doIsEmpty()
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function doIsEmpty() {
|
2016-10-29 07:04:39 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2021-08-09 06:57:44 +00:00
|
|
|
// unclaimed job
|
2023-02-23 13:59:10 +00:00
|
|
|
$found = (bool)$dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( '1' )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( [ 'job_cmd' => $this->type, 'job_token' => '' ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchField();
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2012-12-11 07:48:59 +00:00
|
|
|
|
|
|
|
|
return !$found;
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-14 18:47:06 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doGetSize()
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return int
|
2012-12-14 18:47:06 +00:00
|
|
|
*/
|
|
|
|
|
protected function doGetSize() {
|
|
|
|
|
$key = $this->getCacheKey( 'size' );
|
|
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
$size = $this->wanCache->get( $key );
|
2012-12-14 18:47:06 +00:00
|
|
|
if ( is_int( $size ) ) {
|
|
|
|
|
return $size;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-30 02:02:15 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
|
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2023-02-23 13:59:10 +00:00
|
|
|
$size = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( [ 'job_cmd' => $this->type, 'job_token' => '' ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchRowCount();
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2019-07-06 05:43:45 +00:00
|
|
|
$this->wanCache->set( $key, $size, self::CACHE_TTL_SHORT );
|
2012-12-14 18:47:06 +00:00
|
|
|
|
|
|
|
|
return $size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doGetAcquiredCount()
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return int
|
2012-12-14 18:47:06 +00:00
|
|
|
*/
|
|
|
|
|
protected function doGetAcquiredCount() {
|
2013-02-06 22:45:33 +00:00
|
|
|
if ( $this->claimTTL <= 0 ) {
|
|
|
|
|
return 0; // no acknowledgements
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-14 18:47:06 +00:00
|
|
|
$key = $this->getCacheKey( 'acquiredcount' );
|
|
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
$count = $this->wanCache->get( $key );
|
2012-12-14 18:47:06 +00:00
|
|
|
if ( is_int( $count ) ) {
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 07:04:39 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2023-02-23 13:59:10 +00:00
|
|
|
$count = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->from( 'job' )
|
2023-10-30 19:10:26 +00:00
|
|
|
->where( [
|
|
|
|
|
'job_cmd' => $this->type,
|
|
|
|
|
$dbr->expr( 'job_token', '!=', '' ),
|
|
|
|
|
] )
|
2023-02-23 13:59:10 +00:00
|
|
|
->caller( __METHOD__ )->fetchRowCount();
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2019-07-06 05:43:45 +00:00
|
|
|
$this->wanCache->set( $key, $count, self::CACHE_TTL_SHORT );
|
2012-12-14 18:47:06 +00:00
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-20 19:40:09 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doGetAbandonedCount()
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return int
|
2019-12-14 14:00:55 +00:00
|
|
|
* @throws MWException on database error
|
2013-03-20 19:40:09 +00:00
|
|
|
*/
|
|
|
|
|
protected function doGetAbandonedCount() {
|
|
|
|
|
if ( $this->claimTTL <= 0 ) {
|
|
|
|
|
return 0; // no acknowledgements
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$key = $this->getCacheKey( 'abandonedcount' );
|
|
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
$count = $this->wanCache->get( $key );
|
2013-03-20 19:40:09 +00:00
|
|
|
if ( is_int( $count ) ) {
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 07:04:39 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2023-02-23 13:59:10 +00:00
|
|
|
$count = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where(
|
|
|
|
|
[
|
|
|
|
|
'job_cmd' => $this->type,
|
2023-10-30 19:10:26 +00:00
|
|
|
$dbr->expr( 'job_token', '!=', '' ),
|
2023-10-21 22:01:51 +00:00
|
|
|
$dbr->expr( 'job_attempts', '>=', $this->maxTries ),
|
2023-02-23 13:59:10 +00:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->caller( __METHOD__ )->fetchRowCount();
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2015-10-26 07:41:05 +00:00
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
$this->wanCache->set( $key, $count, self::CACHE_TTL_SHORT );
|
2013-03-20 19:40:09 +00:00
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doBatchPush()
|
2015-10-07 18:03:35 +00:00
|
|
|
* @param IJobSpecification[] $jobs
|
2014-04-16 18:07:26 +00:00
|
|
|
* @param int $flags
|
2012-12-09 03:09:48 +00:00
|
|
|
* @throws DBError|Exception
|
2014-04-16 18:07:26 +00:00
|
|
|
* @return void
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
protected function doBatchPush( array $jobs, $flags ) {
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2017-07-20 03:51:54 +00:00
|
|
|
// In general, there will be two cases here:
|
|
|
|
|
// a) sqlite; DB connection is probably a regular round-aware handle.
|
|
|
|
|
// If the connection is busy with a transaction, then defer the job writes
|
|
|
|
|
// until right before the main round commit step. Any errors that bubble
|
|
|
|
|
// up will rollback the main commit round.
|
2018-04-04 23:29:18 +00:00
|
|
|
// b) mysql/postgres; DB connection is generally a separate CONN_TRX_AUTOCOMMIT handle.
|
2017-07-20 03:51:54 +00:00
|
|
|
// No transaction is active nor will be started by writes, so enqueue the jobs
|
|
|
|
|
// now so that any errors will show up immediately as the interface expects. Any
|
|
|
|
|
// errors that bubble up will rollback the main commit round.
|
|
|
|
|
$fname = __METHOD__;
|
|
|
|
|
$dbw->onTransactionPreCommitOrIdle(
|
2018-04-17 04:39:02 +00:00
|
|
|
function ( IDatabase $dbw ) use ( $jobs, $flags, $fname ) {
|
2017-07-20 03:51:54 +00:00
|
|
|
$this->doBatchPushInternal( $dbw, $jobs, $flags, $fname );
|
|
|
|
|
},
|
|
|
|
|
$fname
|
2017-06-09 02:56:02 +00:00
|
|
|
);
|
2013-04-16 17:43:37 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2013-04-16 17:43:37 +00:00
|
|
|
/**
|
|
|
|
|
* This function should *not* be called outside of JobQueueDB
|
|
|
|
|
*
|
2019-02-17 11:41:11 +00:00
|
|
|
* @suppress SecurityCheck-SQLInjection Bug in phan-taint-check handling bulk inserts
|
2013-11-25 17:12:42 +00:00
|
|
|
* @param IDatabase $dbw
|
2015-10-07 18:03:35 +00:00
|
|
|
* @param IJobSpecification[] $jobs
|
2013-04-16 17:43:37 +00:00
|
|
|
* @param int $flags
|
|
|
|
|
* @param string $method
|
2013-11-25 17:12:42 +00:00
|
|
|
* @throws DBError
|
2014-04-16 18:07:26 +00:00
|
|
|
* @return void
|
2013-04-16 17:43:37 +00:00
|
|
|
*/
|
2013-10-07 16:18:16 +00:00
|
|
|
public function doBatchPushInternal( IDatabase $dbw, array $jobs, $flags, $method ) {
|
2019-01-09 16:24:36 +00:00
|
|
|
if ( $jobs === [] ) {
|
2014-04-16 18:07:26 +00:00
|
|
|
return;
|
2013-04-16 17:43:37 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$rowSet = []; // (sha1 => job) map for jobs that are de-duplicated
|
|
|
|
|
$rowList = []; // list of jobs for jobs that are not de-duplicated
|
2013-04-16 17:43:37 +00:00
|
|
|
foreach ( $jobs as $job ) {
|
2018-07-03 12:42:45 +00:00
|
|
|
$row = $this->insertFields( $job, $dbw );
|
2013-04-16 17:43:37 +00:00
|
|
|
if ( $job->ignoreDuplicates() ) {
|
|
|
|
|
$rowSet[$row['job_sha1']] = $row;
|
|
|
|
|
} else {
|
|
|
|
|
$rowList[] = $row;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $flags & self::QOS_ATOMIC ) {
|
2015-10-07 18:03:35 +00:00
|
|
|
$dbw->startAtomic( $method ); // wrap all the job additions in one transaction
|
2013-04-16 17:43:37 +00:00
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// Strip out any duplicate jobs that are already in the queue...
|
|
|
|
|
if ( count( $rowSet ) ) {
|
2023-02-23 13:59:10 +00:00
|
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'job_sha1' )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where(
|
|
|
|
|
[
|
|
|
|
|
// No job_type condition since it's part of the job_sha1 hash
|
|
|
|
|
'job_sha1' => array_map( 'strval', array_keys( $rowSet ) ),
|
|
|
|
|
'job_token' => '' // unclaimed
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->caller( $method )->fetchResultSet();
|
2013-04-16 17:43:37 +00:00
|
|
|
foreach ( $res as $row ) {
|
2020-06-01 05:00:39 +00:00
|
|
|
wfDebug( "Job with hash '{$row->job_sha1}' is a duplicate." );
|
2013-04-16 17:43:37 +00:00
|
|
|
unset( $rowSet[$row->job_sha1] ); // already enqueued
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Build the full list of job rows to insert
|
|
|
|
|
$rows = array_merge( $rowList, array_values( $rowSet ) );
|
2016-09-05 20:21:26 +00:00
|
|
|
// Insert the job rows in chunks to avoid replica DB lag...
|
2013-04-16 17:43:37 +00:00
|
|
|
foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
|
2023-08-03 20:05:22 +00:00
|
|
|
$dbw->newInsertQueryBuilder()
|
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.
That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.
In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.
So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.
Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 00:06:59 +00:00
|
|
|
->insertInto( 'job' )
|
2023-08-03 20:05:22 +00:00
|
|
|
->rows( $rowBatch )
|
|
|
|
|
->caller( $method )->execute();
|
2013-04-16 17:43:37 +00:00
|
|
|
}
|
2019-03-30 04:41:34 +00:00
|
|
|
$this->incrStats( 'inserts', $this->type, count( $rows ) );
|
|
|
|
|
$this->incrStats( 'dupe_inserts', $this->type,
|
2015-04-20 19:22:30 +00:00
|
|
|
count( $rowSet ) + count( $rowList ) - count( $rows )
|
2013-11-25 17:12:42 +00:00
|
|
|
);
|
2013-04-16 17:43:37 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-04-16 17:43:37 +00:00
|
|
|
}
|
|
|
|
|
if ( $flags & self::QOS_ATOMIC ) {
|
2015-10-07 18:03:35 +00:00
|
|
|
$dbw->endAtomic( $method );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doPop()
|
2022-07-31 00:02:18 +00:00
|
|
|
* @return RunnableJob|false
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
|
|
|
|
protected function doPop() {
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2013-06-19 03:09:10 +00:00
|
|
|
|
2019-03-30 02:02:15 +00:00
|
|
|
$job = false; // job popped off
|
|
|
|
|
try {
|
2013-06-19 03:09:10 +00:00
|
|
|
$uuid = wfRandomString( 32 ); // pop attempt
|
|
|
|
|
do { // retry when our row is invalid or deleted as a duplicate
|
|
|
|
|
// Try to reserve a row in the DB...
|
2016-02-17 09:09:32 +00:00
|
|
|
if ( in_array( $this->order, [ 'fifo', 'timestamp' ] ) ) {
|
2013-06-19 03:09:10 +00:00
|
|
|
$row = $this->claimOldest( $uuid );
|
|
|
|
|
} else { // random first
|
|
|
|
|
$rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
|
|
|
|
|
$gte = (bool)mt_rand( 0, 1 ); // find rows with rand before/after $rand
|
|
|
|
|
$row = $this->claimRandom( $uuid, $rand, $gte );
|
|
|
|
|
}
|
|
|
|
|
// Check if we found a row to reserve...
|
|
|
|
|
if ( !$row ) {
|
|
|
|
|
break; // nothing to do
|
|
|
|
|
}
|
2019-03-30 04:41:34 +00:00
|
|
|
$this->incrStats( 'pops', $this->type );
|
2019-03-30 06:07:48 +00:00
|
|
|
|
2013-06-19 03:09:10 +00:00
|
|
|
// Get the job object from the row...
|
2019-04-26 20:11:09 +00:00
|
|
|
$job = $this->jobFromRow( $row );
|
2013-06-19 03:09:10 +00:00
|
|
|
break; // done
|
|
|
|
|
} while ( true );
|
2015-05-07 03:06:01 +00:00
|
|
|
|
|
|
|
|
if ( !$job || mt_rand( 0, 9 ) == 0 ) {
|
|
|
|
|
// Handled jobs that need to be recycled/deleted;
|
|
|
|
|
// any recycled jobs will be picked up next attempt
|
|
|
|
|
$this->recycleAndDeleteStaleJobs();
|
|
|
|
|
}
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
|
|
|
|
|
return $job;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reserve a row with a single UPDATE without holding row locks over RTTs...
|
2012-10-31 21:34:35 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $uuid 32 char hex string
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param int $rand Random unsigned integer (31 bits)
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param bool $gte Search for job_random >= $random (otherwise job_random <= $random)
|
2022-07-31 00:02:18 +00:00
|
|
|
* @return stdClass|false Row|false
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2012-10-31 21:34:35 +00:00
|
|
|
protected function claimRandom( $uuid, $rand, $gte ) {
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2012-12-13 00:45:02 +00:00
|
|
|
// Check cache to see if the queue has <= OFFSET items
|
2019-07-06 05:43:45 +00:00
|
|
|
$tinyQueue = $this->wanCache->get( $this->getCacheKey( 'small' ) );
|
2012-10-31 21:34:35 +00:00
|
|
|
|
2012-12-13 00:45:02 +00:00
|
|
|
$invertedDirection = false; // whether one job_random direction was already scanned
|
2012-10-31 21:34:35 +00:00
|
|
|
// This uses a replication safe method for acquiring jobs. One could use UPDATE+LIMIT
|
|
|
|
|
// instead, but that either uses ORDER BY (in which case it deadlocks in MySQL) or is
|
2016-10-13 05:34:26 +00:00
|
|
|
// not replication safe. Due to https://bugs.mysql.com/bug.php?id=6980, subqueries cannot
|
2012-10-31 21:34:35 +00:00
|
|
|
// be used here with MySQL.
|
2012-11-01 03:49:58 +00:00
|
|
|
do {
|
2012-12-13 00:45:02 +00:00
|
|
|
if ( $tinyQueue ) { // queue has <= MAX_OFFSET rows
|
|
|
|
|
// For small queues, using OFFSET will overshoot and return no rows more often.
|
|
|
|
|
// Instead, this uses job_random to pick a row (possibly checking both directions).
|
2023-02-23 13:59:10 +00:00
|
|
|
$row = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( self::selectFields() )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where(
|
|
|
|
|
[
|
|
|
|
|
'job_cmd' => $this->type,
|
|
|
|
|
'job_token' => '', // unclaimed
|
2023-10-21 22:16:29 +00:00
|
|
|
$dbw->expr( 'job_random', $gte ? '>=' : '<=', $rand )
|
2023-02-23 13:59:10 +00:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->orderBy(
|
|
|
|
|
'job_random',
|
|
|
|
|
$gte ? SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC
|
|
|
|
|
)
|
|
|
|
|
->caller( __METHOD__ )->fetchRow();
|
2012-12-13 00:45:02 +00:00
|
|
|
if ( !$row && !$invertedDirection ) {
|
|
|
|
|
$gte = !$gte;
|
|
|
|
|
$invertedDirection = true;
|
|
|
|
|
continue; // try the other direction
|
|
|
|
|
}
|
|
|
|
|
} else { // table *may* have >= MAX_OFFSET rows
|
2017-02-20 22:44:19 +00:00
|
|
|
// T44614: "ORDER BY job_random" with a job_random inequality causes high CPU
|
2012-12-13 00:45:02 +00:00
|
|
|
// in MySQL if there are many rows for some reason. This uses a small OFFSET
|
|
|
|
|
// instead of job_random for reducing excess claim retries.
|
2023-02-23 13:59:10 +00:00
|
|
|
$row = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( self::selectFields() )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where(
|
|
|
|
|
[
|
|
|
|
|
'job_cmd' => $this->type,
|
|
|
|
|
'job_token' => '', // unclaimed
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->offset( mt_rand( 0, self::MAX_OFFSET ) )
|
|
|
|
|
->caller( __METHOD__ )->fetchRow();
|
2012-12-13 00:45:02 +00:00
|
|
|
if ( !$row ) {
|
|
|
|
|
$tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
|
2019-07-06 05:43:45 +00:00
|
|
|
$this->wanCache->set( $this->getCacheKey( 'small' ), 1, 30 );
|
2012-12-13 00:45:02 +00:00
|
|
|
continue; // use job_random
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-25 17:12:42 +00:00
|
|
|
|
2019-11-08 16:19:13 +00:00
|
|
|
if ( !$row ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-09 12:19:22 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'job' ) // update by PK
|
|
|
|
|
->set( [
|
2019-11-08 16:19:13 +00:00
|
|
|
'job_token' => $uuid,
|
|
|
|
|
'job_token_timestamp' => $dbw->timestamp(),
|
2023-06-09 12:19:22 +00:00
|
|
|
'job_attempts = job_attempts+1'
|
|
|
|
|
] )
|
|
|
|
|
->where( [
|
|
|
|
|
'job_cmd' => $this->type,
|
|
|
|
|
'job_id' => $row->job_id,
|
|
|
|
|
'job_token' => ''
|
|
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
|
|
|
|
|
2019-11-08 16:19:13 +00:00
|
|
|
// This might get raced out by another runner when claiming the previously
|
|
|
|
|
// selected row. The use of job_random should minimize this problem, however.
|
|
|
|
|
if ( !$dbw->affectedRows() ) {
|
|
|
|
|
$row = false; // raced out
|
2012-10-31 21:34:35 +00:00
|
|
|
}
|
2012-11-01 03:49:58 +00:00
|
|
|
} while ( !$row );
|
2012-10-31 21:34:35 +00:00
|
|
|
|
|
|
|
|
return $row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reserve a row with a single UPDATE without holding row locks over RTTs...
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $uuid 32 char hex string
|
2022-07-31 00:02:18 +00:00
|
|
|
* @return stdClass|false Row|false
|
2012-10-31 21:34:35 +00:00
|
|
|
*/
|
|
|
|
|
protected function claimOldest( $uuid ) {
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2012-10-31 21:34:35 +00:00
|
|
|
|
|
|
|
|
$row = false; // the row acquired
|
2012-11-01 03:49:58 +00:00
|
|
|
do {
|
2012-10-31 21:34:35 +00:00
|
|
|
if ( $dbw->getType() === 'mysql' ) {
|
2016-10-13 05:34:26 +00:00
|
|
|
// Per https://bugs.mysql.com/bug.php?id=6980, we can't use subqueries on the
|
2012-10-31 21:34:35 +00:00
|
|
|
// same table being changed in an UPDATE query in MySQL (gives Error: 1093).
|
2019-08-15 12:21:55 +00:00
|
|
|
// Postgres has no such limitation. However, MySQL offers an
|
2012-10-31 21:34:35 +00:00
|
|
|
// alternative here by supporting ORDER BY + LIMIT for UPDATE queries.
|
2012-10-24 00:29:54 +00:00
|
|
|
$dbw->query( "UPDATE {$dbw->tableName( 'job' )} " .
|
|
|
|
|
"SET " .
|
|
|
|
|
"job_token = {$dbw->addQuotes( $uuid ) }, " .
|
|
|
|
|
"job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
|
|
|
|
|
"job_attempts = job_attempts+1 " .
|
|
|
|
|
"WHERE ( " .
|
|
|
|
|
"job_cmd = {$dbw->addQuotes( $this->type )} " .
|
|
|
|
|
"AND job_token = {$dbw->addQuotes( '' )} " .
|
|
|
|
|
") ORDER BY job_id ASC LIMIT 1",
|
2012-10-31 21:34:35 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// Use a subquery to find the job, within an UPDATE to claim it.
|
|
|
|
|
// This uses as much of the DB wrapper functions as possible.
|
2023-02-23 13:59:10 +00:00
|
|
|
$qb = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'job_id' )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( [ 'job_cmd' => $this->type, 'job_token' => '' ] )
|
|
|
|
|
->orderBy( 'job_id', SelectQueryBuilder::SORT_ASC )
|
|
|
|
|
->limit( 1 );
|
|
|
|
|
|
2023-06-07 22:07:31 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'job' )
|
|
|
|
|
->set( [
|
2013-04-20 17:18:13 +00:00
|
|
|
'job_token' => $uuid,
|
2012-10-24 00:29:54 +00:00
|
|
|
'job_token_timestamp' => $dbw->timestamp(),
|
2023-06-07 22:07:31 +00:00
|
|
|
'job_attempts = job_attempts+1'
|
|
|
|
|
] )
|
|
|
|
|
->where( [ 'job_id = (' . $qb->getSQL() . ')' ] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
2012-10-31 21:34:35 +00:00
|
|
|
}
|
2019-11-08 16:19:13 +00:00
|
|
|
|
|
|
|
|
if ( !$dbw->affectedRows() ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-31 21:34:35 +00:00
|
|
|
// Fetch any row that we just reserved...
|
2023-02-23 13:59:10 +00:00
|
|
|
$row = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( self::selectFields() )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( [ 'job_cmd' => $this->type, 'job_token' => $uuid ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchRow();
|
2019-11-08 16:19:13 +00:00
|
|
|
if ( !$row ) { // raced out by duplicate job removal
|
|
|
|
|
wfDebug( "Row deleted as duplicate by another process." );
|
2012-10-31 21:34:35 +00:00
|
|
|
}
|
2012-11-01 03:49:58 +00:00
|
|
|
} while ( !$row );
|
2012-10-31 21:34:35 +00:00
|
|
|
|
|
|
|
|
return $row;
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doAck()
|
2019-03-30 06:07:48 +00:00
|
|
|
* @param RunnableJob $job
|
2019-12-14 14:00:55 +00:00
|
|
|
* @throws MWException When the job is invalid or on database error.
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2019-03-30 06:07:48 +00:00
|
|
|
protected function doAck( RunnableJob $job ) {
|
2019-03-30 15:05:31 +00:00
|
|
|
$id = $job->getMetadata( 'id' );
|
|
|
|
|
if ( $id === null ) {
|
2012-12-07 03:30:25 +00:00
|
|
|
throw new MWException( "Job of type '{$job->getType()}' has no ID." );
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
|
|
|
|
// Delete a row with a single DELETE without holding row locks over RTTs...
|
2023-06-20 19:31:41 +00:00
|
|
|
$dbw->newDeleteQueryBuilder()
|
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.
That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.
In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.
So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.
Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 00:06:59 +00:00
|
|
|
->deleteFrom( 'job' )
|
2023-06-20 19:31:41 +00:00
|
|
|
->where( [ 'job_cmd' => $this->type, 'job_id' => $id ] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
2015-05-11 23:55:42 +00:00
|
|
|
|
2019-03-30 04:41:34 +00:00
|
|
|
$this->incrStats( 'acks', $this->type );
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-08 22:01:40 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doDeduplicateRootJob()
|
2015-05-23 19:28:35 +00:00
|
|
|
* @param IJobSpecification $job
|
2019-12-14 14:00:55 +00:00
|
|
|
* @throws MWException When a database or job error occurs.
|
2012-11-08 22:01:40 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2015-05-23 19:28:35 +00:00
|
|
|
protected function doDeduplicateRootJob( IJobSpecification $job ) {
|
2019-07-06 05:43:45 +00:00
|
|
|
// Callers should call JobQueueGroup::push() before this method so that if the
|
|
|
|
|
// insert fails, the de-duplication registration will be aborted. Since the insert
|
|
|
|
|
// is deferred till "transaction idle", do the same here, so that the ordering is
|
2012-11-08 22:01:40 +00:00
|
|
|
// maintained. Having only the de-duplication registration succeed would cause
|
|
|
|
|
// jobs to become no-ops without any actual jobs that made them redundant.
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2018-05-09 02:28:39 +00:00
|
|
|
$dbw->onTransactionCommitOrIdle(
|
2019-07-06 05:43:45 +00:00
|
|
|
function () use ( $job ) {
|
|
|
|
|
parent::doDeduplicateRootJob( $job );
|
2016-09-15 21:40:00 +00:00
|
|
|
},
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2012-11-08 22:01:40 +00:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-15 02:29:22 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doDelete()
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function doDelete() {
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2023-06-20 19:31:41 +00:00
|
|
|
$dbw->newDeleteQueryBuilder()
|
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.
That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.
In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.
So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.
Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 00:06:59 +00:00
|
|
|
->deleteFrom( 'job' )
|
2023-06-20 19:31:41 +00:00
|
|
|
->where( [ 'job_cmd' => $this->type ] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2013-05-15 02:29:22 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::doWaitForBackups()
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function doWaitForBackups() {
|
2019-03-09 01:01:30 +00:00
|
|
|
if ( $this->server ) {
|
|
|
|
|
return; // not using LBFactory instance
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-13 02:56:37 +00:00
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
2023-07-31 19:04:01 +00:00
|
|
|
$lbFactory->waitForReplication();
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-06 22:45:33 +00:00
|
|
|
/**
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function doFlushCaches() {
|
2016-02-17 09:09:32 +00:00
|
|
|
foreach ( [ 'size', 'acquiredcount' ] as $type ) {
|
2019-07-06 05:43:45 +00:00
|
|
|
$this->wanCache->delete( $this->getCacheKey( $type ) );
|
2013-02-06 22:45:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:19:38 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::getAllQueuedJobs()
|
2022-11-14 18:51:17 +00:00
|
|
|
* @return Iterator<RunnableJob>
|
2013-02-21 01:19:38 +00:00
|
|
|
*/
|
|
|
|
|
public function getAllQueuedJobs() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return $this->getJobIterator( [ 'job_cmd' => $this->getType(), 'job_token' => '' ] );
|
2015-06-03 20:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see JobQueue::getAllAcquiredJobs()
|
2022-11-14 18:51:17 +00:00
|
|
|
* @return Iterator<RunnableJob>
|
2015-06-03 20:04:42 +00:00
|
|
|
*/
|
|
|
|
|
public function getAllAcquiredJobs() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return $this->getJobIterator( [ 'job_cmd' => $this->getType(), "job_token > ''" ] );
|
2015-06-03 20:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-09 15:41:42 +00:00
|
|
|
/**
|
|
|
|
|
* @see JobQueue::getAllAbandonedJobs()
|
2022-11-14 18:51:17 +00:00
|
|
|
* @return Iterator<RunnableJob>
|
2021-03-09 15:41:42 +00:00
|
|
|
*/
|
|
|
|
|
public function getAllAbandonedJobs() {
|
|
|
|
|
return $this->getJobIterator( [
|
|
|
|
|
'job_cmd' => $this->getType(),
|
|
|
|
|
"job_token > ''",
|
|
|
|
|
"job_attempts >= " . intval( $this->maxTries )
|
|
|
|
|
] );
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 20:04:42 +00:00
|
|
|
/**
|
|
|
|
|
* @param array $conds Query conditions
|
2022-11-14 18:51:17 +00:00
|
|
|
* @return Iterator<RunnableJob>
|
2015-06-03 20:04:42 +00:00
|
|
|
*/
|
|
|
|
|
protected function getJobIterator( array $conds ) {
|
2016-10-29 07:04:39 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
2023-02-23 13:59:10 +00:00
|
|
|
$qb = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( self::selectFields() )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( $conds );
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
|
|
|
|
return new MappedIterator(
|
2023-02-23 13:59:10 +00:00
|
|
|
$qb->caller( __METHOD__ )->fetchResultSet(),
|
2015-06-03 20:04:42 +00:00
|
|
|
function ( $row ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
return $this->jobFromRow( $row );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2013-02-21 01:19:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-04 07:05:19 +00:00
|
|
|
public function getCoalesceLocationInternal() {
|
2019-03-09 01:01:30 +00:00
|
|
|
if ( $this->server ) {
|
|
|
|
|
return null; // not using the LBFactory instance
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return is_string( $this->cluster )
|
2018-10-13 07:29:23 +00:00
|
|
|
? "DBCluster:{$this->cluster}:{$this->domain}"
|
|
|
|
|
: "LBFactory:{$this->domain}";
|
2013-07-04 07:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function doGetSiblingQueuesWithJobs( array $types ) {
|
2016-10-29 07:04:39 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
2015-05-07 03:06:01 +00:00
|
|
|
// @note: this does not check whether the jobs are claimed or not.
|
|
|
|
|
// This is useful so JobQueueGroup::pop() also sees queues that only
|
|
|
|
|
// have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue
|
|
|
|
|
// failed jobs so that they can be popped again for that edge case.
|
2023-02-23 13:59:10 +00:00
|
|
|
$res = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( 'job_cmd' )
|
|
|
|
|
->distinct()
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( [ 'job_cmd' => $types ] )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
2013-07-04 07:05:19 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$types = [];
|
2013-07-04 07:05:19 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$types[] = $row->job_cmd;
|
|
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2013-07-04 07:05:19 +00:00
|
|
|
return $types;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function doGetSiblingQueueSizes( array $types ) {
|
2016-10-29 07:04:39 +00:00
|
|
|
$dbr = $this->getReplicaDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbr );
|
|
|
|
|
|
2023-02-23 13:59:10 +00:00
|
|
|
$res = $dbr->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'job_cmd', 'count' => 'COUNT(*)' ] )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where( [ 'job_cmd' => $types ] )
|
|
|
|
|
->groupBy( 'job_cmd' )
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
2013-07-04 07:05:19 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$sizes = [];
|
2013-07-04 07:05:19 +00:00
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$sizes[$row->job_cmd] = (int)$row->count;
|
|
|
|
|
}
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2013-07-04 07:05:19 +00:00
|
|
|
return $sizes;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 17:47:14 +00:00
|
|
|
/**
|
|
|
|
|
* Recycle or destroy any jobs that have been claimed for too long
|
|
|
|
|
*
|
2013-11-25 17:12:42 +00:00
|
|
|
* @return int Number of jobs recycled/deleted
|
2013-04-09 17:47:14 +00:00
|
|
|
*/
|
|
|
|
|
public function recycleAndDeleteStaleJobs() {
|
|
|
|
|
$now = time();
|
|
|
|
|
$count = 0; // affected rows
|
2021-04-19 01:32:42 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2019-03-30 02:02:15 +00:00
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */
|
|
|
|
|
$scope = $this->getScopedNoTrxFlag( $dbw );
|
2013-04-09 17:47:14 +00:00
|
|
|
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
|
|
|
|
if ( !$dbw->lock( "jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
|
|
|
|
|
return $count; // already in progress
|
|
|
|
|
}
|
2013-04-09 17:47:14 +00:00
|
|
|
|
2013-06-19 03:09:10 +00:00
|
|
|
// Remove claims on jobs acquired for too long if enabled...
|
|
|
|
|
if ( $this->claimTTL > 0 ) {
|
|
|
|
|
$claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
|
|
|
|
|
// Get the IDs of jobs that have be claimed but not finished after too long.
|
|
|
|
|
// These jobs can be recycled into the queue by expiring the claim. Selecting
|
|
|
|
|
// the IDs first means that the UPDATE can be done by primary key (less deadlocks).
|
2023-02-23 13:59:10 +00:00
|
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'job_id' )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where(
|
|
|
|
|
[
|
|
|
|
|
'job_cmd' => $this->type,
|
2023-10-30 19:10:26 +00:00
|
|
|
$dbw->expr( 'job_token', '!=', '' ), // was acquired
|
2023-10-21 22:16:29 +00:00
|
|
|
$dbw->expr( 'job_token_timestamp', '<', $claimCutoff ), // stale
|
|
|
|
|
$dbw->expr( 'job_attempts', '<', $this->maxTries ), // retries left
|
2023-02-23 13:59:10 +00:00
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
->caller( __METHOD__ )->fetchResultSet();
|
2013-06-19 03:09:10 +00:00
|
|
|
$ids = array_map(
|
2021-02-10 22:31:02 +00:00
|
|
|
static function ( $o ) {
|
2013-06-19 03:09:10 +00:00
|
|
|
return $o->job_id;
|
|
|
|
|
}, iterator_to_array( $res )
|
|
|
|
|
);
|
|
|
|
|
if ( count( $ids ) ) {
|
|
|
|
|
// Reset job_token for these jobs so that other runners will pick them up.
|
|
|
|
|
// Set the timestamp to the current time, as it is useful to now that the job
|
|
|
|
|
// was already tried before (the timestamp becomes the "released" time).
|
2023-06-09 12:19:22 +00:00
|
|
|
$dbw->newUpdateQueryBuilder()
|
|
|
|
|
->update( 'job' )
|
|
|
|
|
->set( [
|
2013-06-19 03:09:10 +00:00
|
|
|
'job_token' => '',
|
2019-07-31 02:22:43 +00:00
|
|
|
'job_token_timestamp' => $dbw->timestamp( $now ) // time of release
|
2023-06-09 12:19:22 +00:00
|
|
|
] )
|
|
|
|
|
->where( [
|
|
|
|
|
'job_id' => $ids,
|
2023-10-30 19:10:26 +00:00
|
|
|
$dbw->expr( 'job_token', '!=', '' ),
|
2023-06-09 12:19:22 +00:00
|
|
|
] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
|
|
|
|
|
2014-04-03 00:25:14 +00:00
|
|
|
$affected = $dbw->affectedRows();
|
|
|
|
|
$count += $affected;
|
2019-03-30 04:41:34 +00:00
|
|
|
$this->incrStats( 'recycles', $this->type, $affected );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Just destroy any stale jobs...
|
|
|
|
|
$pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
|
2023-02-23 13:59:10 +00:00
|
|
|
$qb = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( 'job_id' )
|
|
|
|
|
->from( 'job' )
|
|
|
|
|
->where(
|
|
|
|
|
[
|
|
|
|
|
'job_cmd' => $this->type,
|
2023-10-30 19:10:26 +00:00
|
|
|
$dbw->expr( 'job_token', '!=', '' ), // was acquired
|
2023-10-21 22:01:51 +00:00
|
|
|
$dbw->expr( 'job_token_timestamp', '<', $pruneCutoff ) // stale
|
2023-02-23 13:59:10 +00:00
|
|
|
]
|
|
|
|
|
);
|
2013-06-19 03:09:10 +00:00
|
|
|
if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
|
2023-10-30 19:10:26 +00:00
|
|
|
$qb->andWhere( $dbw->expr( 'job_attempts', '>=', $this->maxTries ) );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
|
|
|
|
// Get the IDs of jobs that are considered stale and should be removed. Selecting
|
|
|
|
|
// the IDs first means that the UPDATE can be done by primary key (less deadlocks).
|
2023-02-23 13:59:10 +00:00
|
|
|
$res = $qb->caller( __METHOD__ )->fetchResultSet();
|
2013-04-20 17:18:13 +00:00
|
|
|
$ids = array_map(
|
2021-02-10 22:31:02 +00:00
|
|
|
static function ( $o ) {
|
2013-04-20 17:18:13 +00:00
|
|
|
return $o->job_id;
|
|
|
|
|
}, iterator_to_array( $res )
|
|
|
|
|
);
|
2013-04-09 17:47:14 +00:00
|
|
|
if ( count( $ids ) ) {
|
2023-06-20 19:31:41 +00:00
|
|
|
$dbw->newDeleteQueryBuilder()
|
In query builders, use insertInto() and deleteFrom() instead of insert() and delete()
The design principle for SelectQueryBuilder was to make the chained
builder calls look as much like SQL as possible, so that developers
could leverage their knowledge of SQL to understand what the query
builder is doing.
That's why SelectQueryBuilder::select() takes a list of fields, and by
the same principle, it makes sense for UpdateQueryBuilder::update() to
take a table. However with "insert" and "delete", the SQL designers
chose to add prepositions "into" and "from", and I think it makes sense
to follow that here.
In terms of natural language, we update a table, but we don't delete a
table, or insert a table. We delete rows from a table, or insert rows
into a table. The table is not the object of the verb.
So, add insertInto() as an alias for insert(), and add deleteFrom() as
an alias for delete(). Use the new methods in MW core callers where
PHPStorm knows the type.
Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
2023-09-08 00:06:59 +00:00
|
|
|
->deleteFrom( 'job' )
|
2023-06-20 19:31:41 +00:00
|
|
|
->where( [ 'job_id' => $ids ] )
|
|
|
|
|
->caller( __METHOD__ )->execute();
|
2014-04-03 00:25:14 +00:00
|
|
|
$affected = $dbw->affectedRows();
|
|
|
|
|
$count += $affected;
|
2019-03-30 04:41:34 +00:00
|
|
|
$this->incrStats( 'abandons', $this->type, $affected );
|
2013-04-09 17:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-19 03:09:10 +00:00
|
|
|
$dbw->unlock( "jobqueue-recycle-{$this->type}", __METHOD__ );
|
|
|
|
|
} catch ( DBError $e ) {
|
2019-04-26 20:11:09 +00:00
|
|
|
throw $this->getDBException( $e );
|
2013-04-09 17:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
2014-01-27 21:28:47 +00:00
|
|
|
* @param IJobSpecification $job
|
2018-07-03 12:42:45 +00:00
|
|
|
* @param IDatabase $db
|
2013-10-07 16:18:16 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2018-07-03 12:42:45 +00:00
|
|
|
protected function insertFields( IJobSpecification $job, IDatabase $db ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2013-10-07 16:18:16 +00:00
|
|
|
// Fields that describe the nature of the job
|
2013-11-25 14:38:37 +00:00
|
|
|
'job_cmd' => $job->getType(),
|
2019-03-30 06:07:48 +00:00
|
|
|
'job_namespace' => $job->getParams()['namespace'] ?? NS_SPECIAL,
|
|
|
|
|
'job_title' => $job->getParams()['title'] ?? '',
|
2013-11-25 14:38:37 +00:00
|
|
|
'job_params' => self::makeBlob( $job->getParams() ),
|
2013-10-07 16:18:16 +00:00
|
|
|
// Additional job metadata
|
2018-07-03 12:42:45 +00:00
|
|
|
'job_timestamp' => $db->timestamp(),
|
2015-11-24 22:51:42 +00:00
|
|
|
'job_sha1' => Wikimedia\base_convert(
|
2013-10-07 16:18:16 +00:00
|
|
|
sha1( serialize( $job->getDeduplicationInfo() ) ),
|
|
|
|
|
16, 36, 31
|
|
|
|
|
),
|
2013-11-25 14:38:37 +00:00
|
|
|
'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-10-07 16:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-25 17:12:42 +00:00
|
|
|
* @throws JobQueueConnectionError
|
2019-03-09 01:01:30 +00:00
|
|
|
* @return IDatabase
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2016-10-29 07:04:39 +00:00
|
|
|
protected function getReplicaDB() {
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2016-09-05 19:55:19 +00:00
|
|
|
return $this->getDB( DB_REPLICA );
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBConnectionError $e ) {
|
|
|
|
|
throw new JobQueueConnectionError( "DBConnectionError:" . $e->getMessage() );
|
|
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-11-25 17:12:42 +00:00
|
|
|
* @throws JobQueueConnectionError
|
2019-07-06 05:43:45 +00:00
|
|
|
* @return IMaintainableDatabase
|
2021-09-02 18:43:20 +00:00
|
|
|
* @since 1.37
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2021-04-19 01:32:42 +00:00
|
|
|
protected function getPrimaryDB() {
|
2013-06-19 03:09:10 +00:00
|
|
|
try {
|
2021-04-29 02:37:11 +00:00
|
|
|
return $this->getDB( DB_PRIMARY );
|
2013-06-19 03:09:10 +00:00
|
|
|
} catch ( DBConnectionError $e ) {
|
|
|
|
|
throw new JobQueueConnectionError( "DBConnectionError:" . $e->getMessage() );
|
|
|
|
|
}
|
2012-12-21 01:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-04-19 01:02:08 +00:00
|
|
|
* @param int $index (DB_REPLICA/DB_PRIMARY)
|
2019-07-06 05:43:45 +00:00
|
|
|
* @return IMaintainableDatabase
|
2012-12-21 01:29:02 +00:00
|
|
|
*/
|
|
|
|
|
protected function getDB( $index ) {
|
2019-03-09 01:01:30 +00:00
|
|
|
if ( $this->server ) {
|
|
|
|
|
if ( $this->conn instanceof IDatabase ) {
|
|
|
|
|
return $this->conn;
|
|
|
|
|
} elseif ( $this->conn instanceof DBError ) {
|
|
|
|
|
throw $this->conn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2023-02-23 17:56:12 +00:00
|
|
|
$this->conn = MediaWikiServices::getInstance()->getDatabaseFactory()->create(
|
|
|
|
|
$this->server['type'],
|
|
|
|
|
$this->server
|
|
|
|
|
);
|
2019-03-09 01:01:30 +00:00
|
|
|
} catch ( DBError $e ) {
|
|
|
|
|
$this->conn = $e;
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->conn;
|
|
|
|
|
} else {
|
|
|
|
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
|
|
|
|
$lb = is_string( $this->cluster )
|
|
|
|
|
? $lbFactory->getExternalLB( $this->cluster )
|
|
|
|
|
: $lbFactory->getMainLB( $this->domain );
|
|
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
if ( $lb->getServerType( $lb->getWriterIndex() ) !== 'sqlite' ) {
|
2019-03-09 01:01:30 +00:00
|
|
|
// Keep a separate connection to avoid contention and deadlocks;
|
|
|
|
|
// However, SQLite has the opposite behavior due to DB-level locking.
|
2019-07-06 05:43:45 +00:00
|
|
|
$flags = $lb::CONN_TRX_AUTOCOMMIT;
|
|
|
|
|
} else {
|
2021-12-30 13:03:20 +00:00
|
|
|
// Jobs insertion will be deferred until the PRESEND stage to reduce contention.
|
2019-07-06 05:43:45 +00:00
|
|
|
$flags = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $lb->getMaintenanceConnectionRef( $index, [], $this->domain, $flags );
|
2019-03-09 01:01:30 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-30 02:02:15 +00:00
|
|
|
/**
|
|
|
|
|
* @param IDatabase $db
|
|
|
|
|
* @return ScopedCallback
|
|
|
|
|
*/
|
|
|
|
|
private function getScopedNoTrxFlag( IDatabase $db ) {
|
|
|
|
|
$autoTrx = $db->getFlag( DBO_TRX ); // get current setting
|
|
|
|
|
$db->clearFlag( DBO_TRX ); // make each query its own transaction
|
|
|
|
|
|
2021-02-10 22:31:02 +00:00
|
|
|
return new ScopedCallback( static function () use ( $db, $autoTrx ) {
|
2019-03-30 02:02:15 +00:00
|
|
|
if ( $autoTrx ) {
|
|
|
|
|
$db->setFlag( DBO_TRX ); // restore old setting
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-29 00:01:31 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param string $property
|
2012-08-29 00:01:31 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2012-12-14 18:47:06 +00:00
|
|
|
private function getCacheKey( $property ) {
|
2013-04-21 21:56:20 +00:00
|
|
|
$cluster = is_string( $this->cluster ) ? $this->cluster : 'main';
|
2013-11-25 14:38:37 +00:00
|
|
|
|
2019-07-06 05:43:45 +00:00
|
|
|
return $this->wanCache->makeGlobalKey(
|
2018-10-13 07:29:23 +00:00
|
|
|
'jobqueue',
|
|
|
|
|
$this->domain,
|
|
|
|
|
$cluster,
|
|
|
|
|
$this->type,
|
|
|
|
|
$property
|
|
|
|
|
);
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-07-31 00:02:18 +00:00
|
|
|
* @param array|false $params
|
2012-08-29 00:01:31 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
protected static function makeBlob( $params ) {
|
|
|
|
|
if ( $params !== false ) {
|
|
|
|
|
return serialize( $params );
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-04-26 20:11:09 +00:00
|
|
|
* @param stdClass $row
|
2022-02-26 08:15:27 +00:00
|
|
|
* @return RunnableJob
|
2012-08-29 00:01:31 +00:00
|
|
|
*/
|
2019-04-26 20:11:09 +00:00
|
|
|
protected function jobFromRow( $row ) {
|
|
|
|
|
$params = ( (string)$row->job_params !== '' ) ? unserialize( $row->job_params ) : [];
|
|
|
|
|
if ( !is_array( $params ) ) { // this shouldn't happen
|
|
|
|
|
throw new UnexpectedValueException(
|
|
|
|
|
"Could not unserialize job with ID '{$row->job_id}'." );
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
2019-04-26 20:11:09 +00:00
|
|
|
|
|
|
|
|
$params += [ 'namespace' => $row->job_namespace, 'title' => $row->job_title ];
|
|
|
|
|
$job = $this->factoryJob( $row->job_cmd, $params );
|
|
|
|
|
$job->setMetadata( 'id', $row->job_id );
|
|
|
|
|
$job->setMetadata( 'timestamp', $row->job_timestamp );
|
|
|
|
|
|
|
|
|
|
return $job;
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|
2013-06-19 03:09:10 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param DBError $e
|
2019-04-26 20:11:09 +00:00
|
|
|
* @return JobQueueError
|
2013-06-19 03:09:10 +00:00
|
|
|
*/
|
2019-04-26 20:11:09 +00:00
|
|
|
protected function getDBException( DBError $e ) {
|
|
|
|
|
return new JobQueueError( get_class( $e ) . ": " . $e->getMessage() );
|
2013-06-19 03:09:10 +00:00
|
|
|
}
|
2014-01-02 10:44:23 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the list of job fields that should be selected.
|
|
|
|
|
* @since 1.23
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function selectFields() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-01-02 10:44:23 +00:00
|
|
|
'job_id',
|
|
|
|
|
'job_cmd',
|
|
|
|
|
'job_namespace',
|
|
|
|
|
'job_title',
|
|
|
|
|
'job_timestamp',
|
|
|
|
|
'job_params',
|
|
|
|
|
'job_random',
|
|
|
|
|
'job_attempts',
|
|
|
|
|
'job_token',
|
|
|
|
|
'job_token_timestamp',
|
|
|
|
|
'job_sha1',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-01-02 10:44:23 +00:00
|
|
|
}
|
2012-08-29 00:01:31 +00:00
|
|
|
}
|