本文整理汇总了PHP中JobQueueGroup::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP JobQueueGroup::singleton方法的具体用法?PHP JobQueueGroup::singleton怎么用?PHP JobQueueGroup::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JobQueueGroup
的用法示例。
在下文中一共展示了JobQueueGroup::singleton方法的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: 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;
}
示例3: 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 );
}
示例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: 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)));
}
}
示例6: 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();
}
}
示例7: 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');
}
示例8: 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;
}
示例9: 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
}
示例10: 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;
}
示例11: 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;
}
示例12: 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
});
}
}
示例13: 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;
}
示例14: execute
/**
* Show the special page
*
* @param $params Mixed: parameter(s) passed to the page or null
*/
public function execute($params)
{
$out = $this->getOutput();
$request = $this->getRequest();
$user = $this->getUser();
// If the user doesn't have the required 'SendToFollowers' permission, display an error
if (!$user->isAllowed('SendToFollowers')) {
$out->permissionRequired('SendToFollowers');
return;
}
// Set the page title, robot policies, etc.
$this->setHeaders();
// This feature is available only to logged-in users.
if (!$user->isLoggedIn()) {
$out->setPageTitle($this->msg('boardblastlogintitle')->plain());
$out->addWikiMsg('boardblastlogintext');
return '';
}
// Is the database locked?
if (wfReadOnly()) {
$out->readOnlyPage();
return false;
}
// Blocked through Special:Block? No access for you!
if ($user->isBlocked()) {
$out->blockedPage(false);
return false;
}
// Add CSS & JS
$out->addModuleStyles('ext.socialprofile.userboard.boardblast.css');
$out->addModules('ext.socialprofile.userboard.boardblast.js');
$output = '';
if ($request->wasPosted()) {
$out->setPageTitle($this->msg('messagesenttitle')->plain());
$message = $request->getVal('message');
$user_ids_to = explode(',', $request->getVal('ids'));
$jobParams = array('user_ids_to' => $user_ids_to, 'message' => $message, 'sender' => $user->getId());
$job = new BoardBlastJobs($this->getTitle(), $jobParams);
JobQueueGroup::singleton()->push($job);
$output .= $this->msg('messagesentsuccess')->plain();
} else {
$out->setPageTitle($this->msg('boardblasttitle')->plain());
$output .= $this->displayForm();
}
$out->addHTML($output);
}
示例15: doUpdate
public function doUpdate()
{
global $wgMaxBacklinksInvalidate;
wfProfileIn(__METHOD__);
$job = new HTMLCacheUpdateJob($this->mTitle, array('table' => $this->mTable) + Job::newRootJobParams("htmlCacheUpdate:{$this->mTable}:{$this->mTitle->getPrefixedText()}"));
$count = $this->mTitle->getBacklinkCache()->getNumLinks($this->mTable, 200);
if ($wgMaxBacklinksInvalidate !== false && $count > $wgMaxBacklinksInvalidate) {
wfDebug("Skipped HTML cache invalidation of {$this->mTitle->getPrefixedText()}.");
} elseif ($count >= 200) {
// many backlinks
JobQueueGroup::singleton()->push($job);
JobQueueGroup::singleton()->deduplicateRootJob($job);
} else {
// few backlinks ($count might be off even if 0)
$job->run();
// just do the purge query now
}
wfProfileOut(__METHOD__);
}