MediaWiki REL1_30
runJobs.php
Go to the documentation of this file.
1<?php
24require_once __DIR__ . '/Maintenance.php';
25
27
33class RunJobs extends Maintenance {
34 public function __construct() {
35 parent::__construct();
36 $this->addDescription( 'Run pending jobs' );
37 $this->addOption( 'maxjobs', 'Maximum number of jobs to run', false, true );
38 $this->addOption( 'maxtime', 'Maximum amount of wall-clock time', false, true );
39 $this->addOption( 'type', 'Type of job to run', false, true );
40 $this->addOption( 'procs', 'Number of processes to use', false, true );
41 $this->addOption( 'nothrottle', 'Ignore job throttling configuration', false, false );
42 $this->addOption( 'result', 'Set to JSON to print only a JSON response', false, true );
43 $this->addOption( 'wait', 'Wait for new jobs instead of exiting', false, false );
44 }
45
46 public function memoryLimit() {
47 if ( $this->hasOption( 'memory-limit' ) ) {
48 return parent::memoryLimit();
49 }
50
51 // Don't eat all memory on the machine if we get a bad job.
52 return "150M";
53 }
54
55 public function execute() {
56 if ( $this->hasOption( 'procs' ) ) {
57 $procs = intval( $this->getOption( 'procs' ) );
58 if ( $procs < 1 || $procs > 1000 ) {
59 $this->error( "Invalid argument to --procs", true );
60 } elseif ( $procs != 1 ) {
61 $fc = new ForkController( $procs );
62 if ( $fc->start() != 'child' ) {
63 exit( 0 );
64 }
65 }
66 }
67
68 $outputJSON = ( $this->getOption( 'result' ) === 'json' );
69 $wait = $this->hasOption( 'wait' );
70
71 $runner = new JobRunner( LoggerFactory::getInstance( 'runJobs' ) );
72 if ( !$outputJSON ) {
73 $runner->setDebugHandler( [ $this, 'debugInternal' ] );
74 }
75
76 $type = $this->getOption( 'type', false );
77 $maxJobs = $this->getOption( 'maxjobs', false );
78 $maxTime = $this->getOption( 'maxtime', false );
79 $throttle = !$this->hasOption( 'nothrottle' );
80
81 while ( true ) {
82 $response = $runner->run( [
83 'type' => $type,
84 'maxJobs' => $maxJobs,
85 'maxTime' => $maxTime,
86 'throttle' => $throttle,
87 ] );
88
89 if ( $outputJSON ) {
90 $this->output( FormatJson::encode( $response, true ) );
91 }
92
93 if (
94 !$wait ||
95 $response['reached'] === 'time-limit' ||
96 $response['reached'] === 'job-limit' ||
97 $response['reached'] === 'memory-limit'
98 ) {
99 break;
100 }
101
102 if ( $maxJobs !== false ) {
103 $maxJobs -= count( $response['jobs'] );
104 }
105
106 sleep( 1 );
107 }
108 }
109
113 public function debugInternal( $s ) {
114 $this->output( $s );
115 }
116}
117
118$maintClass = "RunJobs";
119require_once RUN_MAINTENANCE_IF_MAIN;
Class for managing forking command line scripts.
Job queue runner utility methods.
Definition JobRunner.php:40
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
hasOption( $name)
Checks to see if a particular param exists.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
PSR-3 logger instance factory.
Maintenance script that runs pending jobs.
Definition runJobs.php:33
execute()
Do the actual work.
Definition runJobs.php:55
debugInternal( $s)
Definition runJobs.php:113
memoryLimit()
Normally we disable the memory_limit when running admin scripts.
Definition runJobs.php:46
__construct()
Default constructor.
Definition runJobs.php:34
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
Definition hooks.txt:2581
this hook is for auditing only $response
Definition hooks.txt:781
require_once RUN_MAINTENANCE_IF_MAIN
$maintClass
Definition runJobs.php:118