本文整理汇总了PHP中JobQueueGroup类的典型用法代码示例。如果您正苦于以下问题:PHP JobQueueGroup类的具体用法?PHP JobQueueGroup怎么用?PHP JobQueueGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JobQueueGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
function execute()
{
$totalOnly = $this->hasOption('totalonly');
$pendingDBs = JobQueueAggregator::singleton()->getAllReadyWikiQueues();
$sizeByWiki = array();
// (wiki => type => count) map
foreach ($pendingDBs as $type => $wikis) {
foreach ($wikis as $wiki) {
$sizeByWiki[$wiki][$type] = JobQueueGroup::singleton($wiki)->get($type)->getSize();
}
}
if ($this->hasOption('grouponly')) {
$this->output(FormatJSON::encode($sizeByWiki, true) . "\n");
} else {
$total = 0;
foreach ($sizeByWiki as $wiki => $counts) {
$count = array_sum($counts);
if ($count > 0) {
if (!$totalOnly) {
$this->output("{$wiki} {$count}\n");
}
$total += $count;
}
}
if (!$this->hasOption('nototal')) {
$this->output("Total {$total}\n");
}
}
}
示例2: runJobs
private function runJobs()
{
JobQueueGroup::destroySingletons();
$jobs = new RunJobs();
$jobs->loadParamsAndArgs(null, ['quiet' => true], null);
$jobs->execute();
}
示例3: run
function run()
{
global $wgUpdateRowsPerJob;
// Job to update all (or a range of) backlink pages for a page
if (!empty($this->params['recursive'])) {
// Carry over information for de-duplication
$extraParams = $this->getRootJobParams();
// Avoid slave lag when fetching templates.
// When the outermost job is run, we know that the caller that enqueued it must have
// committed the relevant changes to the DB by now. At that point, record the master
// position and pass it along as the job recursively breaks into smaller range jobs.
// Hopefully, when leaf jobs are popped, the slaves will have reached that position.
if (isset($this->params['masterPos'])) {
$extraParams['masterPos'] = $this->params['masterPos'];
} elseif (wfGetLB()->getServerCount() > 1) {
$extraParams['masterPos'] = wfGetLB()->getMasterPos();
} else {
$extraParams['masterPos'] = false;
}
// Convert this into no more than $wgUpdateRowsPerJob RefreshLinks per-title
// jobs and possibly a recursive RefreshLinks job for the rest of the backlinks
$jobs = BacklinkJobUtils::partitionBacklinkJob($this, $wgUpdateRowsPerJob, 1, array('params' => $extraParams));
JobQueueGroup::singleton()->push($jobs);
// Job to update link tables for a set of titles
} elseif (isset($this->params['pages'])) {
foreach ($this->params['pages'] as $pageId => $nsAndKey) {
list($ns, $dbKey) = $nsAndKey;
$this->runForTitle(Title::makeTitleSafe($ns, $dbKey));
}
// Job to update link tables for a given title
} else {
$this->runForTitle($this->title);
}
return true;
}
示例4: execute
public function execute()
{
$group = JobQueueGroup::singleton();
if ($this->hasOption('list')) {
foreach ($group->getQueueTypes() as $type) {
$queue = $group->get($type);
foreach ($queue->getAllQueuedJobs() as $job) {
$this->output($job->toString() . " status=unclaimed\n");
}
foreach ($queue->getAllDelayedJobs() as $job) {
$this->output($job->toString() . " status=delayed\n");
}
}
} elseif ($this->hasOption('group')) {
foreach ($group->getQueueTypes() as $type) {
$queue = $group->get($type);
$delayed = $queue->getDelayedCount();
$pending = $queue->getSize();
$claimed = $queue->getAcquiredCount();
$abandoned = $queue->getAbandonedCount();
$active = max(0, $claimed - $abandoned);
if ($pending + $claimed + $delayed > 0) {
$this->output("{$type}: {$pending} queued; " . "{$claimed} claimed ({$active} active, {$abandoned} abandoned); " . "{$delayed} delayed\n");
}
}
} else {
$count = 0;
foreach ($group->getQueueTypes() as $type) {
$count += $group->get($type)->getSize();
}
$this->output("{$count}\n");
}
}
示例5: fixRedirects
/**
* Insert jobs into the job queue to fix redirects to the given title
* @param string $reason the reason for the fix, see message "double-redirect-fixed-<reason>"
* @param $redirTitle Title: the title which has changed, redirects pointing to this title are fixed
* @param bool $destTitle Not used
*/
public static function fixRedirects( $reason, $redirTitle, $destTitle = false ) {
# Need to use the master to get the redirect table updated in the same transaction
$dbw = wfGetDB( DB_MASTER );
$res = $dbw->select(
array( 'redirect', 'page' ),
array( 'page_namespace', 'page_title' ),
array(
'page_id = rd_from',
'rd_namespace' => $redirTitle->getNamespace(),
'rd_title' => $redirTitle->getDBkey()
), __METHOD__ );
if ( !$res->numRows() ) {
return;
}
$jobs = array();
foreach ( $res as $row ) {
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
if ( !$title ) {
continue;
}
$jobs[] = new self( $title, array(
'reason' => $reason,
'redirTitle' => $redirTitle->getPrefixedDBkey() ) );
# Avoid excessive memory usage
if ( count( $jobs ) > 10000 ) {
JobQueueGroup::singleton()->push( $jobs );
$jobs = array();
}
}
JobQueueGroup::singleton()->push( $jobs );
}
示例6: doUpdate
/**
* Purges the list of URLs passed to the constructor.
*/
public function doUpdate()
{
global $wgCdnReboundPurgeDelay;
self::purge($this->urls);
if ($wgCdnReboundPurgeDelay > 0) {
JobQueueGroup::singleton()->lazyPush(new CdnPurgeJob(Title::makeTitle(NS_SPECIAL, 'Badtitle/' . __CLASS__), array('urls' => $this->urls, 'jobReleaseTimestamp' => time() + $wgCdnReboundPurgeDelay)));
}
}
示例7: insert
/**
* Usually this job is fast enough to be executed immediately,
* in which case having it go through jobqueue only causes problems
* in installations with errant job queue processing.
* @override
*/
public function insert()
{
global $wgTranslateDelayedMessageIndexRebuild;
if ($wgTranslateDelayedMessageIndexRebuild) {
JobQueueGroup::singleton()->push($this);
} else {
$this->run();
}
}
示例8: testInsertDelayed
public function testInsertDelayed()
{
global $wgTranslateDelayedMessageIndexRebuild;
$wgTranslateDelayedMessageIndexRebuild = true;
MessageIndexRebuildJob::newJob()->insert();
$job = JobQueueGroup::singleton()->get('MessageIndexRebuildJob')->pop();
$this->assertInstanceOf('MessageIndexRebuildJob', $job, 'There is a job in the JobQueue');
$this->assertTrue($job->run(), 'Job is executed succesfully');
}
示例9: run
public function run()
{
foreach ($this->params['jobsByWiki'] as $wiki => $jobMaps) {
$jobSpecs = array();
foreach ($jobMaps as $jobMap) {
$jobSpecs[] = JobSpecification::newFromArray($jobMap);
}
JobQueueGroup::singleton($wiki)->push($jobSpecs);
}
return true;
}
示例10: execute
public function execute()
{
global $wgTitle;
if ($this->hasOption('procs')) {
$procs = intval($this->getOption('procs'));
if ($procs < 1 || $procs > 1000) {
$this->error("Invalid argument to --procs", true);
}
$fc = new ForkController($procs);
if ($fc->start() != 'child') {
exit(0);
}
}
$maxJobs = $this->getOption('maxjobs', false);
$maxTime = $this->getOption('maxtime', false);
$startTime = time();
$type = $this->getOption('type', false);
$wgTitle = Title::newFromText('RunJobs.php');
$dbw = wfGetDB(DB_MASTER);
$n = 0;
$group = JobQueueGroup::singleton();
do {
$job = $type === false ? $group->pop() : $group->get($type)->pop();
// job from a single queue
if ($job) {
// found a job
// Perform the job (logging success/failure and runtime)...
$t = microtime(true);
$this->runJobsLog($job->toString() . " STARTING");
$status = $job->run();
$group->ack($job);
// done
$t = microtime(true) - $t;
$timeMs = intval($t * 1000);
if (!$status) {
$this->runJobsLog($job->toString() . " t={$timeMs} error={$job->error}");
} else {
$this->runJobsLog($job->toString() . " t={$timeMs} good");
}
// Break out if we hit the job count or wall time limits...
if ($maxJobs && ++$n >= $maxJobs) {
break;
}
if ($maxTime && time() - $startTime > $maxTime) {
break;
}
// Don't let any slaves/backups fall behind...
$group->get($type)->waitForBackups();
}
} while ($job);
// stop when there are no jobs
}
示例11: run
public function run()
{
if ($this->params['usleep'] > 0) {
usleep($this->params['usleep']);
}
if ($this->params['lives'] > 1) {
$params = $this->params;
$params['lives']--;
$job = new self($this->title, $params);
JobQueueGroup::singleton()->push($job);
}
return true;
}
示例12: run
/**
* Queue some more jobs!
*
* @return bool
*/
public function run()
{
$data = $this->params['data'];
$pages = $this->params['pages'];
$jobsByTarget = array();
foreach ($pages as $page) {
$title = Title::newFromText($page['title']);
$jobsByTarget[$page['wiki']][] = new MassMessageJob($title, $data);
}
foreach ($jobsByTarget as $wiki => $jobs) {
JobQueueGroup::singleton($wiki)->push($jobs);
}
return true;
}
示例13: doUpdate
public function doUpdate()
{
$job = new HTMLCacheUpdateJob($this->mTitle, array('table' => $this->mTable, 'recursive' => true) + Job::newRootJobParams("htmlCacheUpdate:{$this->mTable}:{$this->mTitle->getPrefixedText()}"));
$count = $this->mTitle->getBacklinkCache()->getNumLinks($this->mTable, 100);
if ($count >= 100) {
// many backlinks
JobQueueGroup::singleton()->lazyPush($job);
} else {
// few backlinks ($count might be off even if 0)
$dbw = wfGetDB(DB_MASTER);
$dbw->onTransactionIdle(function () use($job) {
$job->run();
// just do the purge query now
});
}
}
示例14: run
/**
* Run a refreshLinks2 job
* @return boolean success
*/
function run()
{
global $wgUpdateRowsPerJob;
$linkCache = LinkCache::singleton();
$linkCache->clear();
if (is_null($this->title)) {
$this->error = "refreshLinks2: Invalid title";
return false;
}
// Back compat for pre-r94435 jobs
$table = isset($this->params['table']) ? $this->params['table'] : 'templatelinks';
// Avoid slave lag when fetching templates.
// When the outermost job is run, we know that the caller that enqueued it must have
// committed the relevant changes to the DB by now. At that point, record the master
// position and pass it along as the job recursively breaks into smaller range jobs.
// Hopefully, when leaf jobs are popped, the slaves will have reached that position.
if (isset($this->params['masterPos'])) {
$masterPos = $this->params['masterPos'];
} elseif (wfGetLB()->getServerCount() > 1) {
$masterPos = wfGetLB()->getMasterPos();
} else {
$masterPos = false;
}
$tbc = $this->title->getBacklinkCache();
$jobs = array();
// jobs to insert
if (isset($this->params['start']) && isset($this->params['end'])) {
# This is a partition job to trigger the insertion of leaf jobs...
$jobs = array_merge($jobs, $this->getSingleTitleJobs($table, $masterPos));
} else {
# This is a base job to trigger the insertion of partitioned jobs...
if ($tbc->getNumLinks($table, $wgUpdateRowsPerJob + 1) <= $wgUpdateRowsPerJob) {
# Just directly insert the single per-title jobs
$jobs = array_merge($jobs, $this->getSingleTitleJobs($table, $masterPos));
} else {
# Insert the partition jobs to make per-title jobs
foreach ($tbc->partition($table, $wgUpdateRowsPerJob) as $batch) {
list($start, $end) = $batch;
$jobs[] = new RefreshLinksJob2($this->title, array('table' => $table, 'start' => $start, 'end' => $end, 'masterPos' => $masterPos) + $this->getRootJobParams());
}
}
}
if (count($jobs)) {
JobQueueGroup::singleton()->push($jobs);
}
return true;
}
示例15: testTemplateCategories
function testTemplateCategories()
{
$title = Title::newFromText("Categorized from template");
$page = WikiPage::factory($title);
$user = new User();
$user->mRights = array('createpage', 'edit', 'purge');
$page->doEditContent(new WikitextContent('{{Categorising template}}'), 'Create a page with a template', 0, false, $user);
$this->assertEquals(array(), $title->getParentCategories());
$template = WikiPage::factory(Title::newFromText('Template:Categorising template'));
$template->doEditContent(new WikitextContent('[[Category:Solved bugs]]'), 'Add a category through a template', 0, false, $user);
// Run the job queue
JobQueueGroup::destroySingletons();
$jobs = new RunJobs();
$jobs->loadParamsAndArgs(null, array('quiet' => true), null);
$jobs->execute();
$this->assertEquals(array('Category:Solved_bugs' => $title->getPrefixedText()), $title->getParentCategories());
}