Avoid deprecated usage of Job::factory()
Change-Id: Ia2b8b71159ed8d387ae31f921ddcfd0d9136118c
This commit is contained in:
parent
33cfe2e139
commit
83cdb69ed2
3 changed files with 29 additions and 8 deletions
|
|
@ -21,6 +21,8 @@
|
|||
* @defgroup JobQueue JobQueue
|
||||
*/
|
||||
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
||||
use MediaWiki\JobQueue\JobFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\RequestTimeout\TimeoutException;
|
||||
use Wikimedia\UUID\GlobalIdGenerator;
|
||||
|
||||
|
|
@ -57,6 +59,8 @@ abstract class JobQueue {
|
|||
/** @var bool */
|
||||
protected $typeAgnostic;
|
||||
|
||||
private JobFactory $jobFactory;
|
||||
|
||||
protected const QOS_ATOMIC = 1; // integer; "all-or-nothing" job insertions
|
||||
|
||||
protected const ROOTJOB_TTL = 2419200; // integer; seconds to remember root jobs (28 days)
|
||||
|
|
@ -102,6 +106,8 @@ abstract class JobQueue {
|
|||
if ( $this->typeAgnostic ) {
|
||||
$this->type = 'default';
|
||||
}
|
||||
|
||||
$this->jobFactory = MediaWikiServices::getInstance()->getJobFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -736,8 +742,7 @@ abstract class JobQueue {
|
|||
* @return Job
|
||||
*/
|
||||
protected function factoryJob( $command, $params ) {
|
||||
// @TODO: dependency inject this as a callback
|
||||
return Job::factory( $command, $params );
|
||||
return $this->jobFactory->newJob( $command, $params );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ class SiteStatsTest extends MediaWikiIntegrationTestCase {
|
|||
$this->setService( 'MainWANObjectCache', $cache );
|
||||
$jobq = $this->getServiceContainer()->getJobQueueGroup();
|
||||
|
||||
$jobq->push( Job::factory( 'null', Title::newMainPage(), [] ) );
|
||||
$jobq->push( new NullJob( [] ) );
|
||||
$this->assertSame( 1, SiteStats::jobs(),
|
||||
'A single job enqueued bumps jobscount stat to 1' );
|
||||
|
||||
$jobq->push( Job::factory( 'null', Title::newMainPage(), [] ) );
|
||||
$jobq->push( new NullJob( [] ) );
|
||||
$this->assertSame( 1, SiteStats::jobs(),
|
||||
'SiteStats::jobs() count does not reflect addition ' .
|
||||
'of a second job (cached)'
|
||||
|
|
|
|||
|
|
@ -380,13 +380,29 @@ class JobQueueTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
protected function newJob( $i = 0, $rootJob = [] ) {
|
||||
return Job::factory( 'null', Title::newMainPage(),
|
||||
[ 'lives' => 0, 'usleep' => 0, 'removeDuplicates' => 0, 'i' => $i ] + $rootJob );
|
||||
$params = [
|
||||
'namespace' => NS_MAIN,
|
||||
'title' => 'Main_Page',
|
||||
'lives' => 0,
|
||||
'usleep' => 0,
|
||||
'removeDuplicates' => 0,
|
||||
'i' => $i
|
||||
] + $rootJob;
|
||||
|
||||
return $this->getServiceContainer()->getJobFactory()->newJob( 'null', $params );
|
||||
}
|
||||
|
||||
protected function newDedupedJob( $i = 0, $rootJob = [] ) {
|
||||
return Job::factory( 'null', Title::newMainPage(),
|
||||
[ 'lives' => 0, 'usleep' => 0, 'removeDuplicates' => 1, 'i' => $i ] + $rootJob );
|
||||
$params = [
|
||||
'namespace' => NS_MAIN,
|
||||
'title' => 'Main_Page',
|
||||
'lives' => 0,
|
||||
'usleep' => 0,
|
||||
'removeDuplicates' => 1,
|
||||
'i' => $i
|
||||
] + $rootJob;
|
||||
|
||||
return $this->getServiceContainer()->getJobFactory()->newJob( 'null', $params );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue