Manual:Job queue/For developers
From MediaWiki.org
To use the job queue to do your deferred updates, you need to do these things:
[edit] Create a Job subclass
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; } }
[edit] Add your Job class to the global list
// The key is your job identifier (from the Job constructor), the value is your class name $wgJobClasses['synchroniseThreadArticleData'] = 'SynchroniseThreadArticleDataJob';
[edit] How to invoke a deferred update
// Figure out your Job parameters (goes in $this->params) $jobParams = array( 'limit' => $limit, 'cascade' => true ); // Figure out the 'Title' to execute the job on. $title = $article->getTitle(); // Instantiate a Job object, and insert it into the database. $job = new SynchroniseThreadArticleDataJob( $title, $jobParams ); $job->insert();