Commit graph

71 commits

Author SHA1 Message Date
Máté Szabó
f414f8f91b jobqueue: expand architecture documentation
Why:

- The JobQueue docs currently do not describe the
  semantics of handling job execution failures.
- Some other features, such as job deduplication, enqueue semantics and
  the overall execution flow, are also missing from the architecture
  document.

What:

- Expand the JobQueue architecture document to describe how jobs that
  return false from Job::run() or complete exceptionally are treated.
- Rework some preexisting sections of the same document for brevity.
- Describe JobSpecification and JobQueueGroup in the same document.
- Describe the different between push() and lazyPush() semantics.
- Describe the execution flow of a Job.
- Briefly summarize how job deduplication is expected to function.

Change-Id: Ib0c1f165feabefe862710b28977b598faf637ec5
2024-10-17 22:14:07 +00:00
Adam Wight
188d2cbbb0 Remove unchecked exception annotations
Callers should not catch an unchecked exception, so it doesn't belong
in a function signature.  Unchecked exceptions indicate a coding error,
which by definition the code will not be able to handle correctly.

If any of these exceptions were supposed to be in response to an edge
case, user input, or initial conditions, then they should be changed
to a runtime error.  If the exception class cannot be changed, then
the annotation should include a comment explaining its purpose and
prognosis.

Bug: T240672
Change-Id: I2e640b9737cb68090a8e1cb70067d1b74037d647
2024-09-17 22:20:58 +02:00
Bartosz Dziewoński
df4cbf5ac6 Replace gettype() with get_debug_type() in debug/log/test output
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

In this commit I'm only changing code where it looks like the result
is used only for some king of debug, log, or test output. This
probably won't break anything important, but I'm not sure whether
anything might depend on the exact values.

Change-Id: I7c1f0a8f669228643e86f8e511c0e26a2edb2948
2024-07-31 19:33:57 +02:00
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
Timo Tijhof
ce96bed119 jobqueue: combine Logger channels, improve docs, add missing ingroup tags
* combine `JobQueueFederated` and `JobQueueRedis` into a single
  `JobQueue` channel.

* Remove duplicate descriptions from file blocks in favour of class
  doc blocks. This reduces needless duplication and was often
  incorrect or outdated, and helps (ironically) to make the file header
  more consistently visually ignorable. Various files in this patch
  contained bogus copy-pasta descriptions from unrelated classes,
  and re-defined `defgroup JobQueue` many times, showing exactly
  how this is defacto ignored and counter-productive to maintain
  in two places.

  Remove `ingroup` from file blocks in class files as otherwise
  the file is indexed twice (e.g. in Doxygen) which makes navigation
  on doc.wikimedia.org rather messy for classes in this group.

  Ref <https://gerrit.wikimedia.org/r/q/message:ingroup+is:merged>

Change-Id: I926a3aec2bc98fefa1075c4a794c46108579ae3f
2024-03-25 15:00:38 -07:00
Gergő Tisza
6114f847e7 JobSpecification: Inherit request ID
Make JobSpecification inherit the request ID of the queuing
request just like Job does. This makes it easier to find log
events for actions that are triggered by a web request but happen
via jobs. Especially useful for enqueueable updates which might
or might not happen via jobs depending on the load of the system
at the moment.

Bug: T351729
Change-Id: I965ee211b00b2b33970651368930b5c59704a827
Depends-On: Iccf0f3bf666b9a77fbbd5874fe2f56bfffc9bd4c
Depends-On: I9613c8c293ac3fb4b1ac25c229bb4dc83e2f34fa
2023-11-30 19:37:52 +00:00
Amir Sarabadani
5bd33d46ef Reorg: Move WebRequest to includes\Request
This has been approved as part of RFC T166010

Bug: T321882
Change-Id: I6bbdbbe6ea48cc1f50bc568bb8780fc7c5361a6f
2023-09-11 21:44:34 +01:00
Tim Starling
317b460500 Fix even more PHPStorm inspections (#3)
* Inappropriate @inheritDoc usage. Arguably all @inheritDoc is
  inappropriate but these are the ones PHPStorm flags as misleading
  due to the method not being inherited.
* Doc comment type does not match actual argument/return type.
* I replaced "@return void|never" with "@return void" since never means
  never, it doesn't make sense for it to be conditional. If a method
  can return (even if that is unlikely) then @return contains the type
  that it returns. "@return never" means that there is no such type
  because the method never returns.
* Incomplete/partial/broken doc tags

Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
2023-03-25 00:30:15 +00:00
jenkins-bot
b566089775 Merge "jobqueue: Strip line break from Job::toString debug log line" 2023-03-23 20:50:30 +00:00
Youri
9ec64a1ee0 jobqueue: Strip line break from Job::toString debug log line
Removing newline characters from job parameter values since newlines
indicate a new log line in larger logfiles.

Change-Id: Ia99a9e580ff9e61f16718b79b37b7b0bf1cf639c
2023-03-23 20:24:16 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
daniel
d9003dd275 Add dependency injection for Job classes
Introduces JobFactory

Bug: T245900
Change-Id: I094cc9325e5eaf2717ae510ef988a72407195224
2023-01-19 15:44:11 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Thiemo Kreuz
67c56155c7 Replace trivial usages of code in strings with concatenation
This is really hard to read. What is code, what is string? These
places are so simple, they really don't need the "{$var}" syntax.

Change-Id: I589dedb8c0193eec4eef500bbb896b5b790b727b
2022-08-26 12:26:44 +00:00
Mark A. Hershberger
46db606eff Ensure we don't pass null to mb_strlen.
Seen in RefreshSecondaryDataUpdateTest::testEnqueueOnFailure()

Bug: T289926
Change-Id: I22eb808ab27e702033c4df05ec299554f944590b
2022-07-12 10:03:55 -04:00
Aryeh Gregor
747bc81ac0 Use MainConfigNames instead of string literals
Part 1, proof of concept. Hundreds of files left to go. These changes
brought to you in large part by vim macros.

Bug: T305805
Change-Id: I44789091e9f6394c800a11b29f22528c8dcacf71
2022-04-11 17:53:27 +03:00
Umherirrender
68808e5832 Replace deprecated JobQueueGroup::singleton()
Change-Id: Icdb301d352d302f70fefba9b40df2368cb217fd2
2022-01-27 21:37:50 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Siddharth VP
60faebb725 Fix typos in comments (I-J)
Change-Id: Icaea2b6665cfc3b811d94f70c93452237f5e72bf
2021-12-30 20:38:04 +05:30
Petr Pchelko
a747229116 Remove Title param typehints from jobs
Change-Id: I8d8407d704eac97d4b0574369e315e28e23a89a8
2021-06-07 09:52:46 -07:00
Gergő Tisza
20b0b50d48
Document Job's required constructor signature
Change-Id: I2f374169f2b55a7be03507ce1f1c838428b56b75
2020-11-18 01:33:15 -08:00
jenkins-bot
39705eb311 Merge "Replace "@stable for subclassing" with "@stable to extend"" 2020-07-13 09:31:38 +00:00
jenkins-bot
0270990f0b Merge "Replace "@stable for calling" by "@stable to call"" 2020-07-13 09:27:04 +00:00
daniel
3c50afa46b Replace "@stable for subclassing" with "@stable to extend"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
2020-07-13 11:00:30 +02:00
daniel
f7116bb3a2 Replace "@stable for overriding" with "@stable to override"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
2020-07-13 10:57:12 +02:00
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
7572a152fc Annotate extensible classes.
This marks some base classes as stable for subclassing.

Bug: T247862
Change-Id: I7b77075849aa40960f2486b463e498a3ea8058e9
2020-07-09 11:07:38 +02:00
Derick Alangi
52a21ace03 Fix method/function names case mismatch in core files
PHP doesn't care much but I think we humans do because we should
call methods by the name we give them. Method fixed are;

- isOk() -> isOK()
- setOk() -> setOK()
- teardown() -> tearDown()

Change-Id: I6b3f0cf3902887058efa426968da380803869e0b
2019-08-31 23:17:51 +00:00
Aaron Schulz
2c74f7205b jobqueue: mention more methods in RunnableJob to fix various IDEA warnings
Change-Id: I156411062ae7831c935869d226fc4934bde55107
2019-07-05 21:02:17 -07:00
Máté Szabó
c8854dd1fe Job: Fix typo in exception message for invalid specification
The Job::factory method throws an InvalidArgumentException if a given
job specification is invalid. The error message for this exception was
worded in correctly. This patch improves the message to avoid confusion.

Change-Id: I6cab739263c1d3530c0650823db022dd5a4b60bc
2019-05-26 14:22:45 +02:00
Timo Tijhof
4dce644596 jobqueue: Follow-up for fc5d51f129 (added GenericParameterJob)
* Remove duplicate $params check from Job::factory done in Job::__construct.

* In Job::factory(), restore use of a valid title as default for passing as
  constructor arg to old job classes. Their constructor may expect it to
  be valid.
  Keep the invalid dummy in Job::__construct, and document why.

* tests: Update test case for failure mode when using Job::factory
  with a class that requires a title. It asserted getting an invalid
  title. This now restores the behaviour prior to fc5d51f129,
  which is that job classes that require a title, get a valid one.

* tests: Remove test case for testToString that used
  an explicitly passed but invalid params value. I've converted
  that to expect the exception we now throw instead.

* tests: Update getMockJob(), also used by testToString, which was
  relying on undocumented behaviour that 'new Title' is public
  and gets namespace=0 and title=''. Before fc5d51f129,
  title params weren't in toString() and it asserted outputting
  three spaces (delimiter, empty string from formatted title,
  delimiter).
  In fc5d51f129, this changed to asserting "Special:" which
  seems unintentional as we didn't pass it the internally reserved
  NS_SPECIAL/'' value, and yet was caught by the dbkey=='' check.
  Given this test case doesn't deal with titles, omit it for now.

  A job can either have a $title and title/namespace in params,
  or neither. This test was asserting an in-memory scenario
  where $title can be an object, but title/namespace absent from
  params.

Bug: T221368
Depends-On: I89f6ad6967d6f82d87a62c15c0dded901c51b714
Change-Id: I2ec99a12ecc627359a2aae5153d5d7c54156ff46
2019-04-25 15:44:11 +00:00
Aaron Schulz
fc5d51f129 jobqueue: add GenericParameterJob and RunnableJob interface
Simplify the code of jobs that do not care about titles and removes
the direct Title dependency from JobQueue. Remove getTitle() from
IJobSpecification itself. Move all the Job::factory calls into a
single JobQueue::factoryJob() method.

Depends-on: Iee78f4baeca0c0b4d6db073f2fbcc56855114ab0
Change-Id: I9c9d0726d4066bb0aa937665847ad6042ade13ec
2019-04-08 11:05:23 -07:00
Timo Tijhof
a94c300c0a jobqueue: Change internal $params logic to teach Phan (3)
Follows-up 9b4938c40d, 4bff6f1558, and 766549999c.

It seems despite being optional and documented as 'array|Title',
Phan still thinks it is wrong to pass Title.

Try removing the explicit default of empty array,
the lower code already does this anyway.

This should fix build failures that are preventing merges
in repos where Phan is finding Job::__construct(string, Title)
where it currently fails as follows:

 CompileArticleMetadataJob.php:11
 PhanTypeMismatchArgument Argument 2 (params) is …\Title|string but
 \Job::__construct() takes array

Change-Id: I1c3aee273e0917e30b9c18b49b24fc7f966ff57c
2019-04-05 18:01:12 +00:00
Timo Tijhof
766549999c jobqueue: Document Title as valid param type for compat (2)
Follows-up 9b4938c40d, and 4bff6f1558. The latter of which
updated ::factory() instead of __construct(). Oops.

This should fix build failures that are preventing merges
in repos where Phan is finding Job::__construct(string, Title)
where it currently fails as follows:

 CompileArticleMetadataJob.php:11
 PhanTypeMismatchArgument Argument 2 (params) is …\Title|string but
 \Job::__construct() takes array

As Phan is reading the php doc I guess.

Change-Id: I128d57ead6bcb9dbae99d41a1f23192c3f6fbdba
2019-04-05 17:02:11 +01:00
Timo Tijhof
4bff6f1558 jobqueue: Document Title as valid param type for compat
Follows-up 9b4938c40d.

This should fix build failures that are preventing merges
in repos where Phan is finding Job::__construct(string, Title)
where it currently fails as follows:

 CompileArticleMetadataJob.php:11
 PhanTypeMismatchArgument Argument 2 (params) is …\Title|string but
 \Job::__construct() takes array

As Phan is reading the php doc I guess.

Change-Id: I94b442f06b6858d136546bf22f2465cf8f071ab0
2019-04-05 01:11:10 +01:00
Aaron Schulz
a51ea350be Add Job::getMetadata() and Job::setMetadata() accessors
Change-Id: I3a97008d324f600a1c9f6005673073277ee564fa
2019-04-03 16:34:32 +00:00
jenkins-bot
c81d40df04 Merge "Make Job::hasExecutionFlag() actually work" 2019-03-29 22:54:58 +00:00
Aaron Schulz
9b4938c40d jobqueue: simplify the signature of Job::factory() and Job::__construct()
Remove the $title argument from these methods to simplify subclasses that
do not have a meaningful title to use. The Job::getTitle() method can be
overriden by subclasses to return something meaningful.

The old call signature is still supported for backwards compatibility.
This will automatically determine what getTitle() returns as before.

Use "Blankpage" as the "not applicable" title for jobs instead of one
that looks like some error occured.

Change-Id: I3d5bd012d9cef1e7daaccfb0d5d319552eb89fb6
2019-03-29 13:15:58 -07:00
Aaron Schulz
895306b8ce Make Job::hasExecutionFlag() actually work
Change-Id: I7d32edd5913e12a3380ca9f7f5a318e1682725bf
2019-03-28 18:54:29 -07:00
Derick Alangi
f8337198ce Job::factory should throw an InvalidArgumentException, not MWException
Change-Id: I9a85562b205db604d2746ec5db0e72dacdb93c6d
2019-02-11 23:35:47 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
James D. Forrester
f8ac266287 Job: Remove insert() and batchInsert(), deprecated since 1.21
Bug: T179624
Change-Id: I0d78a926c8c513fd652a424e8a51ded20e524a4a
2018-05-21 20:10:09 +01:00
Aaron Schulz
c6b668c2ec Do not start explicit transaction rounds for RecentChangesUpdateJob
The replaces the hacky use of onTransactionIdle(), which no longer runs
immediately in explicit transaction rounds since d4c31cf841.

Also clarified TransactionRoundDefiningUpdate comment about rounds.

Change-Id: Ie17eacdcaea4e47019cc94e1c7beed9d7fec5cf2
2018-04-17 12:39:05 +00:00
James D. Forrester
970557f89d Job::insert: Hard deprecate (soft-deprecated in 1.21!)
Change-Id: I5b653a3dacd6dc73a80b6bbcc282fdd5dad6e49a
2017-11-02 15:07:39 -07:00
Lucas Werkmeister
a57252a1f5 Allow callback functions for creating jobs
$wgJobClasses can now specify a factory function for creating a job,
instead of a class to be instantiated directly. This makes it possible
to inject services in a job constructor, and register a factory function
that calls the constructor with default services.

This follows Ieb85493a7765 and Ia2107dc5af78, which introduced factory
functions for API modules and special pages.

Change-Id: I0461e59da2a8fa6681e3b1fcdfc38bfed7f3ac32
2017-05-09 19:26:13 +02:00
Gergő Tisza
d304f5e394 Pass Job success status to teardown callbacks
Change-Id: Icf2e03efcfd9232fe4ead776096b61cef1c06141
2016-10-05 02:55:45 +00:00
Erik Bernhardson
afc3b5a120 Track which web request created a job
We currently push a request id into structured logging (monolog/
logstash) to allow seeing all logs that were triggered by the same
request. This extends that to pass the id through jobs so jobs triggered
by a web request also share the same id and can be tracked together.
This web request id will follow jobs both directly created by a request,
and jobs created by those jobs.

This should give us some more visibility when debugging into what
started a particular job, and if a large number of jobs blowing up the
job queue are somehow related.

Change-Id: Iedbd031e6e9bb18fd6f7b923c8c305102255ab4b
2016-04-13 10:41:13 -07:00
Aaron Schulz
4a28737c32 Make Job::toString() handle array parameters better
Previously it would result in array(x) in fairly simple cases.

Change-Id: I6bfe67faa45835babb2c7e259b5cd158e0f0a649
2016-03-16 03:45:35 -07:00
jenkins-bot
d716155c8b Merge "Reset scoped session for upload jobs after deferred updates" 2016-03-01 11:30:55 +00:00