Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F112667268
DrydockLeaseUpdateWorker.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
Mon, May 12, 03:33
Size
1 KB
Mime Type
text/x-php
Expires
Wed, May 14, 03:33 (2 d)
Engine
blob
Format
Raw Data
Handle
26123903
Attached To
rPH Phabricator
DrydockLeaseUpdateWorker.php
View Options
<?php
final
class
DrydockLeaseUpdateWorker
extends
DrydockWorker
{
protected
function
doWork
()
{
$lease_phid
=
$this
->
getTaskDataValue
(
'leasePHID'
);
$hash
=
PhabricatorHash
::
digestForIndex
(
$lease_phid
);
$lock_key
=
'drydock.lease:'
.
$hash
;
$lock
=
PhabricatorGlobalLock
::
newLock
(
$lock_key
)
->
lock
(
1
);
try
{
$lease
=
$this
->
loadLease
(
$lease_phid
);
$this
->
updateLease
(
$lease
);
}
catch
(
Exception
$ex
)
{
$lock
->
unlock
();
throw
$ex
;
}
$lock
->
unlock
();
}
private
function
updateLease
(
DrydockLease
$lease
)
{
if
(!
$lease
->
canUpdate
())
{
return
;
}
$this
->
checkLeaseExpiration
(
$lease
);
$commands
=
$this
->
loadCommands
(
$lease
->
getPHID
());
foreach
(
$commands
as
$command
)
{
if
(!
$lease
->
canUpdate
())
{
break
;
}
$this
->
processCommand
(
$lease
,
$command
);
$command
->
setIsConsumed
(
true
)
->
save
();
}
$this
->
yieldIfExpiringLease
(
$lease
);
}
private
function
processCommand
(
DrydockLease
$lease
,
DrydockCommand
$command
)
{
switch
(
$command
->
getCommand
())
{
case
DrydockCommand
::
COMMAND_RELEASE
:
$this
->
releaseLease
(
$lease
);
break
;
}
}
private
function
releaseLease
(
DrydockLease
$lease
)
{
$lease
->
openTransaction
();
$lease
->
setStatus
(
DrydockLeaseStatus
::
STATUS_RELEASED
)
->
save
();
// TODO: Hold slot locks until destruction?
DrydockSlotLock
::
releaseLocks
(
$lease
->
getPHID
());
$lease
->
saveTransaction
();
PhabricatorWorker
::
scheduleTask
(
'DrydockLeaseDestroyWorker'
,
array
(
'leasePHID'
=>
$lease
->
getPHID
(),
),
array
(
'objectPHID'
=>
$lease
->
getPHID
(),
));
$resource
=
$lease
->
getResource
();
$blueprint
=
$resource
->
getBlueprint
();
$blueprint
->
didReleaseLease
(
$resource
,
$lease
);
}
}
Event Timeline
Log In to Comment