Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4105924
RebuildMessageIndexJob.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
RebuildMessageIndexJob.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\MessageLoading
;
use
GenericParameterJob
;
use
MediaWiki\Extension\Translate\Jobs\GenericTranslateJob
;
use
MediaWiki\Extension\Translate\MessageGroupProcessing\MessageGroups
;
use
MediaWiki\Extension\Translate\Services
;
use
MediaWiki\MediaWikiServices
;
/**
* Job for rebuilding message index.
* @author Niklas Laxström
* @copyright Copyright © 2011-2013, Niklas Laxström
* @license GPL-2.0-or-later
* @ingroup JobQueue
*/
class
RebuildMessageIndexJob
extends
GenericTranslateJob
implements
GenericParameterJob
{
public
static
function
newJob
(
?
string
$caller
=
null
):
self
{
$timestamp
=
microtime
(
true
);
return
new
self
(
[
'timestamp'
=>
$timestamp
,
'caller'
=>
$caller
??
wfGetCaller
(),
]
);
}
/** @inheritDoc */
public
function
__construct
(
$params
=
[]
)
{
parent
::
__construct
(
'RebuildMessageIndexJob'
,
$params
);
$this
->
removeDuplicates
=
true
;
}
public
function
run
():
bool
{
$lb
=
MediaWikiServices
::
getInstance
()->
getDBLoadBalancerFactory
();
if
(
!
$lb
->
waitForReplication
()
)
{
$this
->
logWarning
(
'Continuing despite replication lag'
);
}
// Make sure we have latest version of message groups from global cache.
// This should be pretty fast, just a few cache fetches with some post processing.
MessageGroups
::
singleton
()->
clearProcessCache
();
// BC for existing jobs which may not have this parameter set
$timestamp
=
$this
->
getParams
()[
'timestamp'
]
??
microtime
(
true
);
try
{
Services
::
getInstance
()->
getMessageIndex
()->
rebuild
(
$timestamp
);
}
catch
(
MessageIndexException
$e
)
{
// Currently there is just one type of exception: lock wait time exceeded.
// Assuming no bugs, this is a transient issue and retry will solve it.
$this
->
logWarning
(
$e
->
getMessage
()
);
// Try again later. See ::allowRetries
return
false
;
}
return
true
;
}
public
function
allowRetries
():
bool
{
// This is the default, but added for explicitness and clarity
return
true
;
}
public
function
getDeduplicationInfo
():
array
{
$info
=
parent
::
getDeduplicationInfo
();
// The timestamp is different for every job, so ignore it. The worst that can
// happen is that the front cache is not cleared until a future job is created.
// There is a check in MessageIndex to spawn a new job if timestamp is smaller
// than expected.
//
// Ideally we would take the latest timestamp, but it seems that the job queue
// just prevents insertion of duplicate jobs instead.
unset
(
$info
[
'params'
][
'timestamp'
]
);
unset
(
$info
[
'params'
][
'caller'
]
);
return
$info
;
}
}
class_alias
(
RebuildMessageIndexJob
::
class
,
'MessageIndexRebuildJob'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Aug 18, 19:13 (2 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
4f/80/01550f7e2e3ca5c3029451ef812f
Default Alt Text
RebuildMessageIndexJob.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment