Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F68939709
HarbormasterTargetWorker.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
Sat, Jun 29, 14:06
Size
2 KB
Mime Type
text/x-php
Expires
Mon, Jul 1, 14:06 (2 d)
Engine
blob
Format
Raw Data
Handle
18650660
Attached To
rPH Phabricator
HarbormasterTargetWorker.php
View Options
<?php
/**
* Execute a build target.
*/
final
class
HarbormasterTargetWorker
extends
HarbormasterWorker
{
public
function
getRequiredLeaseTime
()
{
// This worker performs actual build work, which may involve a long wait
// on external systems.
return
phutil_units
(
'24 hours in seconds'
);
}
private
function
loadBuildTarget
()
{
$data
=
$this
->
getTaskData
();
$id
=
idx
(
$data
,
'targetID'
);
$target
=
id
(
new
HarbormasterBuildTargetQuery
())
->
withIDs
(
array
(
$id
))
->
setViewer
(
$this
->
getViewer
())
->
executeOne
();
if
(!
$target
)
{
throw
new
PhabricatorWorkerPermanentFailureException
(
pht
(
'Bad build target ID "%d".'
,
$id
));
}
return
$target
;
}
public
function
doWork
()
{
$target
=
$this
->
loadBuildTarget
();
$build
=
$target
->
getBuild
();
$viewer
=
$this
->
getViewer
();
try
{
$status_pending
=
HarbormasterBuildTarget
::
STATUS_PENDING
;
if
(
$target
->
getTargetStatus
()
==
$status_pending
)
{
$target
->
setTargetStatus
(
HarbormasterBuildTarget
::
STATUS_BUILDING
);
$target
->
save
();
}
$implementation
=
$target
->
getImplementation
();
$implementation
->
execute
(
$build
,
$target
);
$next_status
=
HarbormasterBuildTarget
::
STATUS_PASSED
;
if
(
$implementation
->
shouldWaitForMessage
(
$target
))
{
$next_status
=
HarbormasterBuildTarget
::
STATUS_WAITING
;
}
$target
->
setTargetStatus
(
$next_status
);
$target
->
save
();
}
catch
(
PhabricatorWorkerYieldException
$ex
)
{
// If the target wants to yield, let that escape without further
// processing. We'll resume after the task retries.
throw
$ex
;
}
catch
(
Exception
$ex
)
{
phlog
(
$ex
);
try
{
$log
=
$build
->
createLog
(
$target
,
'core'
,
'exception'
);
$start
=
$log
->
start
();
$log
->
append
((
string
)
$ex
);
$log
->
finalize
(
$start
);
}
catch
(
Exception
$log_ex
)
{
phlog
(
$log_ex
);
}
$target
->
setTargetStatus
(
HarbormasterBuildTarget
::
STATUS_FAILED
);
$target
->
save
();
}
id
(
new
HarbormasterBuildEngine
())
->
setViewer
(
$viewer
)
->
setBuild
(
$build
)
->
continueBuild
();
}
}
Event Timeline
Log In to Comment