Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97257601
PhabricatorSearchWorker.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jan 3, 20:31
Size
2 KB
Mime Type
text/x-php
Expires
Sun, Jan 5, 20:31 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23366882
Attached To
rPH Phabricator
PhabricatorSearchWorker.php
View Options
<?php
final
class
PhabricatorSearchWorker
extends
PhabricatorWorker
{
public
static
function
queueDocumentForIndexing
(
$phid
,
$parameters
=
null
)
{
if
(
$parameters
===
null
)
{
$parameters
=
array
();
}
parent
::
scheduleTask
(
__CLASS__
,
array
(
'documentPHID'
=>
$phid
,
'parameters'
=>
$parameters
,
),
array
(
'priority'
=>
parent
::
PRIORITY_IMPORT
,
'objectPHID'
=>
$phid
,
));
}
protected
function
doWork
()
{
$data
=
$this
->
getTaskData
();
$object_phid
=
idx
(
$data
,
'documentPHID'
);
$object
=
$this
->
loadObjectForIndexing
(
$object_phid
);
$engine
=
id
(
new
PhabricatorIndexEngine
())
->
setObject
(
$object
);
$parameters
=
idx
(
$data
,
'parameters'
,
array
());
$engine
->
setParameters
(
$parameters
);
if
(!
$engine
->
shouldIndexObject
())
{
return
;
}
$key
=
"index.{$object_phid}"
;
$lock
=
PhabricatorGlobalLock
::
newLock
(
$key
);
try
{
$lock
->
lock
(
1
);
}
catch
(
PhutilLockException
$ex
)
{
// If we fail to acquire the lock, just yield. It's expected that we may
// contend on this lock occasionally if a large object receives many
// updates in a short period of time, and it's appropriate to just retry
// rebuilding the index later.
throw
new
PhabricatorWorkerYieldException
(
15
);
}
try
{
// Reload the object now that we have a lock, to make sure we have the
// most current version.
$object
=
$this
->
loadObjectForIndexing
(
$object
->
getPHID
());
$engine
->
setObject
(
$object
);
$engine
->
indexObject
();
}
catch
(
Exception
$ex
)
{
$lock
->
unlock
();
if
(!(
$ex
instanceof
PhabricatorWorkerPermanentFailureException
))
{
$ex
=
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Failed to update search index for document "%s": %s'
,
$object_phid
,
$ex
->
getMessage
()));
}
throw
$ex
;
}
$lock
->
unlock
();
}
private
function
loadObjectForIndexing
(
$phid
)
{
$viewer
=
PhabricatorUser
::
getOmnipotentUser
();
$object
=
id
(
new
PhabricatorObjectQuery
())
->
setViewer
(
$viewer
)
->
withPHIDs
(
array
(
$phid
))
->
executeOne
();
if
(!
$object
)
{
throw
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Unable to load object "%s" to rebuild indexes.'
,
$phid
));
}
return
$object
;
}
}
Event Timeline
Log In to Comment