Manual:Job queue/For developers
From MediaWiki.org
To use the job queue to do your deferred updates, you need to do these things:
Create a Job subclass [edit]
You need to create a class, that, given parameters and a Title, will perform your deferred updates
<?php class SynchroniseThreadArticleDataJob extends Job { public function __construct( $title, $params ) { // Replace synchroniseThreadArticleData with an identifier for your job. parent::__construct( 'synchroniseThreadArticleData', $title, $params ); } /** * Execute the job * * @return bool */ public function run() { // Load data from $this->params and $this->title $article = new Article( $this->title, 0 ); $limit = $this->params['limit']; $cascade = $this->params['cascade']; // Perform your updates if ( $article ) { Threads::synchroniseArticleData( $article, $limit, $cascade ); } return true; } }
Add your Job class to the global list [edit]
// The key is your job identifier (from the Job constructor), the value is your class name $wgJobClasses['synchroniseThreadArticleData'] = 'SynchroniseThreadArticleDataJob';
How to invoke a deferred update [edit]
/** * 1. Set any job parameters you want to have available when your job runs * * this can also be an empty array() * these values will be available to your job via $this->params[''param_name'] */ $jobParams = array( 'limit' => $limit, 'cascade' => true ); /** * 2. Get the article title that the job will use when running * * if you have no article title to use you can use : * Title::newMainPage(); -> a vague, dumby title * Title::newFromText('User:UserName/SynchroniseThreadArticleData') -> a more specific dumby title * * the idea is for the db to have a title reference that will be used by your job to create/update a title * or for troubleshooting by having a title reference that is not vague */ $title = $article->getTitle(); /** * 3. Instantiate a Job object */ $job = new SynchroniseThreadArticleDataJob( $title, $jobParams ); /** * 4. Insert the job into the database * note the differences in the mediawiki versions */ $job->insert(); // mediawiki < 1.21 JobQueueGroup::singleton()->push( $job ); // mediawiki >= 1.21