Commit graph

113 commits

Author SHA1 Message Date
Tim Starling
6ce4044fe1 Make runJobs.php die peacefully if the DB server goes away
Connection loss with a failure to reconnect led to a variety of failure
modes, such as an assertion from getBindingHandle() when addQuotes() is
next called. And Maintenance::shutdown() was calling
commitPrimaryChanges() three times, each call leading to an assertion
due to the round stage being broken.

So, try to exit promptly if a DBConnectionError is caught, by
introducing a new "reached" category for fatal exceptions. Guard the
calls to commitPrimaryChanges(), and skip the call prior to shutdown()
since shutdown() calls it already.

Change-Id: I81ee9017a58adac674a9495802f6bd4bcc22ee61
2022-02-10 15:17:43 +11:00
Ppchelko
44edde6295 Reapply "SettingsBuilder: allow maintenance scripts to manipulate config"
This reverts commit 4f7a4a2477.

Reason for revert: This change is good, just need some preparation in extensions.

Depends-On: I24221be2cedfa132fc94d39d72e4a133cc3cdb12
Depends-On: I5e6119b650e581c6aa5a1132aa071b49cff8b8ca
Change-Id: I5a5a9000751fa3914c9d432eb49475091b3bdb80
2022-01-26 19:21:58 +00:00
Ppchelko
4f7a4a2477 Revert "SettingsBuilder: allow maintenance scripts to manipulate config"
This reverts commit a652f306a5.

Reason for revert: need to prepare extensions first

Change-Id: Iccedf38a8dc964db7c49fd51c971912655122081
2022-01-26 17:24:31 +00:00
daniel
a652f306a5 SettingsBuilder: allow maintenance scripts to manipulate config
Maintenance scripts often need to manipulate configuration settings.
This introduces a way to do this cleanly via SettingsBuilder,
removing the need to rely on global variables.

Bug: T294739
Bug: T294742
Bug: T300128
Change-Id: Ibf443fd564bbbf388cce8ab4dabba55ebca0dfa4
2022-01-26 12:02:56 +00:00
Umherirrender
94792e97be maintenance: Cleanup use of exit in Maintenance::execute implementation
Returning void from execute() is success.
Returning true is success, false is failure with exit(1)
Using fatalError also using exit(1)

Change-Id: I1d40430ad6226e4aab8f0810b03ee1213282d123
2021-08-30 19:48:27 +00:00
Ammarpad
8270e5ef99 ForkController: Throw more meaningful error for missing PHP extensions
Currently all the signal constants emit warnings as they are undefined
in PHP 7.4 and throw fatal error in PHP 8, if pcntl is not available.

pcntl extension is not enabled by default, and is not required by
MediaWiki, so this class should throw a better error if it's not
found. The class already has comment that pcntl and posix are required
but this is meaningless since the error and a warning for each constant
would be emitted anyway.

https://www.php.net/manual/en/pcntl.installation.php

Convert RESTARTABLE_SIGNALS constant back to static property as it was,
because we can only use these constants after confirming they exist,
which happens in the constructor.

Bug: T280456
Change-Id: I66deaa9b346b936b2628ac0511492d20a42fea6c
2021-04-17 22:21:15 +01:00
Tim Starling
20d06b34bb Safer autoloading with respect to file-scope code
Many files were in the autoloader despite having potentially harmful
file-scope code.

* Exclude all CommandLineInc maintenance scripts from the autoloader.
* Introduce  "NO_AUTOLOAD" tag which excludes the file containing it
  from the autoloader. Use it on CommandLineInc.php and a few
  suspicious-looking files without classes in case they are refactored
  to add classes in the future.
* Add a test which parses all non-PSR4 class files and confirms that
  they do not contain dangerous file-scope code. It's slow (15s) but
  its results were enlightening.
* Several maintenance scripts define constants in the file scope,
  intending to modify the behaviour of MediaWiki. Either move the
  define() to a later setup function, or protect with NO_AUTOLOAD.
* Use require_once consistently with Maintenance.php and
  doMaintenance.php, per the original convention which is supposed to
  allow one maintenance script to use the class of another maintenance
  script. Using require breaks autoloading of these maintenance class
  files.
* When Maintenance.php is included, check if MediaWiki has already
  started, and if so, return early. Revert the fix for T250003 which
  is incompatible with this safety measure. Hopefully it was superseded
  by splitting out the class file.
* In runScript.php add a redundant PHP_SAPI check since it does some
  things in file-scope code before any other check will be run.
* Change the if(false) class_alias(...) to something more hackish and
  more compatible with the new test.
* Some site-related scripts found Maintenance.php in a non-standard way.
  Use the standard way.
* fileOpPerfTest.php called error_reporting(). Probably debugging code
  left in; removed.
* Moved mediawiki.compress.7z registration from the class file to the
  caller.

Change-Id: I1b1be90343a5ab678df6f1b1bdd03319dcf6537f
2021-01-11 11:59:36 +11:00
Petr Pchelko
0f87f5885c Convert JobRunner into a service and use DI
Bug: T246156
Change-Id: If4f67a6fa0e26ade3fc0420e62fa836c2a3e4b2e
2020-02-27 08:04:48 -08:00
Aaron Schulz
2859306684 Refactor edit stashing into a PageEditStash service
Additional code cleanup:
* Call setCacheTime() in parseAndStash instead of relying
  on the one in DerivedPageDataUpdater.
* Improve the SPI logging by adding more extra fields.
* Treat requests in CLI/job mode (aside from tests) like
  those from bots with regard to checking the stash.
  This should avoid stats/logging pollution.

Change-Id: I8c6be919e399378e401a60502add0ecec7764d2d
2019-04-17 12:53:03 -07:00
Aaron Schulz
ae3559f83f Do not return invalid JSON in runJobs.php
Change-Id: Ib94c23bfc5e599a628a5fd65bb14baf750874995
2019-03-29 20:44:56 -07:00
RazeSoldier
66cebd0be7 runJobs.php output something when the job queue is empty
If the job queue is empty, output "Job queue is empty."

Bug: T187628
Change-Id: I7d0925bd2995526b1a67148096e9543766a62da7
2019-03-17 12:48:35 +00:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Bryan Davis
9e34eeff23 Maintenance: add fatalError() method
Deprecate the second argument to Maintenance::error() in favor of a new
Maintenance::fatalError() method. This is intended to make it easier to
review flow control in maintenance scripts.

Change-Id: I75699008638f7e99b11210c7bb9e2e131fca7c9e
2017-11-21 21:34:16 -07:00
Aaron Schulz
25ae9afb9b Make runJobs.php treat --json value as case insensitive
The docs mentioned "JSON", which did not actually work.

Change-Id: Ie9802551d05f7d80d1db0fd316e36f4b35bbc521
2017-10-25 07:41:22 +00:00
Aaron Schulz
d8c63d0ae5 Define MEDIAWIKI_JOB_RUNNER in runJobs.php
This is the same value used by the WMF /rpc entrypoint.

Change-Id: I146a36c76ff2136e5fa9b768673987ebd611403c
2017-10-09 10:10:13 -07:00
Aaron Schulz
6c73b32fd5 Convert JobRunner to using beginMasterChanges()
This lets the runJobs.php $wgCommandLineMode hack be removed.

Some fixes based on unit tests:
* Only call applyTransactionRoundFlags() for master connections
  for transaction rounds from beginMasterChanges().
* Also cleaned up the commitAndWaitForReplication() reset logic.
* Removed deprecated DataUpdate::doUpdate() calls from jobs
  since they cannot nest in a transaction round.

Change-Id: Ia9b91f539dc11a5c05bdac4bcd99d6615c4dc48d
2016-09-07 03:56:37 +00:00
Niklas Laxström
e2fde0fe45 Add --wait option for runJobs.php
It is now very easy to implement a simple low delay job runner:

while true; do php runJobs.php --wait; sleep 1; done;

Change-Id: I50cf00aed4b15d90384a2cc12bddd64d96d5a1ad
2016-02-21 09:24:39 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Aaron Schulz
7f1d4dfb0e Enable DBO_TRX for runJobs.php, just like HTTP job runner
Change-Id: Ic6fa2f9f0d18aeeb15f482e2faab2ebc56650570
2015-04-21 17:42:31 -07:00
Aaron Schulz
e9a65a5194 Removed redundant wfReadOnly check in runJobs.php
* JobRunner handles this and doing it pre-fork is less safe

Change-Id: I9e53e6b2d04f3f370723af8140e796ba337cfd3b
2015-04-21 23:22:36 +00:00
Bryan Davis
1195e11a8a Move MWLogger classes to MediaWiki\Logger namespace
Move the MWLogger PSR-3 logging related classes into the
MediaWiki\Logger namespace. Create shim classes to ease migration of
existing MWLoggerFactory usage to the namespaced classes.

Bug: T93406
Change-Id: I359cc81fbd2dcf8937742311dcc7d3dee08747b0
2015-04-03 11:32:24 -07:00
Bryan Davis
2eea1d5a42 Convert JobRunner to PSR-3 logger
* Implement Psr\Log\LoggerAwareInterface
* Categorize log events with levels (debug, info, error)

Bug: T87521
Change-Id: I2637c40a44e396b1020b76f54c2e8b931f764f02
2015-01-26 15:04:12 -08:00
Aaron Schulz
baaf489633 Set "has value" flag correctly for result parameter
Change-Id: I97eeef620ddfdda6f09abbfdf0388146d4d02e36
2014-07-28 17:38:56 -07:00
Aaron Schulz
5dc6ff0f36 Added support for result=json parameter to runJobs.php
* This can let the caller get info about what was run, just like the web version

Change-Id: I49d7eccee52eb1dc161249fdc0546259ccf1f959
2014-07-28 10:30:18 -07:00
Aaron Schulz
094d901b88 Refactored duplicated code into JobRunner.php
* Also added an async flag to SpecialRunJobs so that it can be
  set to false to get a JSON blob back with a regular 200 status.

Change-Id: I2f5763e017684c3c61f3d3f27ddf7f7834bdfce2
2014-07-25 17:28:10 +00:00
Aaron Schulz
2979f0b6f1 Avoid useless delay and master connections in wfWaitForSlaves() in runJobs.php
* Some jobs, like Parsoid ones, do not actually do master DB updates

Change-Id: I1a8830eafd7760d081df966bb423030dcdc96408
2014-07-19 15:19:40 -07:00
Aaron Schulz
76b8f81419 Made --maxtime a soft limit again
* The new job loop already manages timeouts and this version caused
  some problems with the time-sharing approach that used --maxtime.
  This killed runners too fast for some jobs and only handled CPU
  time anyway, not wall clock time.

Change-Id: Id3462554b1ecba9ecdf7d49673645d54c0555cd6
2014-07-18 11:01:01 -07:00
Aaron Schulz
ca1a36bfe3 Use job backoff times in the case of high failure rates
Change-Id: Ica0c81bfb127e858ec6f1aa193da351930493b2d
2014-07-15 17:22:39 -07:00
Gergo Tisza
c1a60bfb8e Allow floating point values for $wgJobBackoffThrottling
Useful for jobs which take longer than a second to finish.

Change-Id: I2e57d61fd67b97fbd593274b31e1bfada8f522f5
2014-05-09 00:40:21 +00:00
Aaron Schulz
d1723b7820 Disable job throttling for DuplicateJob jobs
Change-Id: I461ea9710660d061ae2da1f99f39247877332ca2
2014-04-28 23:18:25 +00:00
Siebrand Mazeland
606c680b21 Update formatting in maintenance/ (4/4)
Change-Id: I6b58d014a4bfd6600e4e6f80188fdcfce18482ca
2014-04-23 20:09:26 +02:00
Siebrand Mazeland
89d8c583d7 Pass phpcs-strict on maintenance/ (2/8)
Change-Id: I69e2bca3c98fe9d3713c852699f49b7b4c868338
2014-04-22 21:25:47 +00:00
umherirrender
e78776373e Fixed some @params documentation (maintenance)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I727deec35a712de0f0c676cc87dfa661f1ee965b
2014-04-17 22:48:32 +02:00
jenkins-bot
35b2d649a9 Merge "Made runJobs.php fully respect $wgJobBackoffThrottling" 2014-04-08 16:15:30 +00:00
Brian Wolff
2ab242ae0f Rollback transaction in case of uncaught exceptions during job
If there is an unhandled exception during a job, rollback the
transaction to be safe. Otherwise its likely that the
transaction will be commited when next job is run, as $dbw->begin()
implicitly commits any open pending transactions. This can result
in database referential integrity issues.

Change-Id: I5807e64440ff6c6651fbbb4924645d05d843b98e
2014-04-05 23:02:02 -03:00
Aaron Schulz
0929a1fba8 Made runJobs.php fully respect $wgJobBackoffThrottling
* Previously, it did not if --type was used
* A --nothrottle option was added to ignore throttling

Change-Id: Ib3ca899f1ce30250a63084096f1b660c96e359fe
2014-04-02 18:20:16 -07:00
Chad Horohoe
518fa756f2 Remove $wgTitle from all maintenance scripts
Shouldn't be needed and aren't for any core operations. If any
extension relies on these $wgTitles being set in maintenance
environments those extensions are broken and should be fixed.

Change-Id: Ie02a5042ab96e155d783d56d5340dd0da8e3d55c
2014-03-12 18:28:47 -07:00
Aaron Schulz
256beb9200 Fixed silly regression with $job not being set in runJobs.php
Change-Id: I2dae31574e5822b7b76bf1b04aba0063bed17944
2013-12-28 16:07:25 -08:00
Aaron Schulz
e8cb20737a Added $wgJobBackoffThrottling to replace wmf sleep() hack
* This also adds a Job::workItemCount() method
* Removed unused USE_PRIORITY constant
* A few small cleanups in runJobs.php

Change-Id: Ife9370e488fa63dcd1f702ed98f3b7f26057f10c
2013-12-23 15:10:50 -08:00
Antoine Musso
670cc77d20 runbJobs: rm outdated options in comments
We had a comment at the top of runJobs.php listing potential options to
use. That unsurprisingly ended up being outdated. Instead folks should
either:

* page down to the constructor to have the exhaustive list of options
* RTFM by invoking the script with --help

Change-Id: Ic87574b26145376bb9926894a7c35f9f0622a3e9
2013-12-17 23:32:25 +01:00
umherirrender
24bfde2710 Fix spacing and break some lines
Change-Id: Ia57685d8858e02e399ad5c75ce64d12609d340ac
2013-08-24 17:06:25 +02:00
jenkins-bot
7465a1b83d Merge "Made runJobs.php respect time limits better and try to bail before OOMs" 2013-08-13 18:09:10 +00:00
Aaron Schulz
a50f3e7f7a Removed unused $dbw variable and connection
Change-Id: I47060139fe762257847f482d24bd284fe6123452
2013-08-13 00:42:09 -07:00
Aaron Schulz
1bdb0c8501 Made runJobs.php respect time limits better and try to bail before OOMs
Change-Id: I93b9cebda591f15d42c401f4dc51ecd746d45a0d
2013-06-27 09:50:03 -07:00
Aaron Schulz
f52950c33e Include the backtrace in the log for job exceptions
Change-Id: Iff478f452142f1ccc9af70b4a64cfb66d04014f3
2013-06-25 23:16:05 +00:00
Aaron Schulz
e990facd73 Actually update $lastTime in runJobs.php
Change-Id: Ic51b0941aa72f444b1bad919e6a05ff0ba273ce7
2013-05-24 18:09:45 +00:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Aaron Schulz
294e591a3c Make sure job runner exceptions get logged.
Change-Id: Ie468e7009c45a2b637df38309fd7b8368e021b6d
2013-05-16 13:51:36 -07:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00