private function loadWorkingCopyLease(DrydockRepositoryOperation $operation)
 {
     $viewer = $this->getViewer();
     // TODO: This is very similar to leasing in Harbormaster, maybe we can
     // share some of the logic?
     $lease_phid = $operation->getProperty('exec.leasePHID');
     if ($lease_phid) {
         $lease = id(new DrydockLeaseQuery())->setViewer($viewer)->withPHIDs(array($lease_phid))->executeOne();
         if (!$lease) {
             throw new PhabricatorWorkerPermanentFailureException(pht('Lease "%s" could not be loaded.', $lease_phid));
         }
     } else {
         $working_copy_type = id(new DrydockWorkingCopyBlueprintImplementation())->getType();
         $repository = $operation->getRepository();
         $allowed_phids = $repository->getAutomationBlueprintPHIDs();
         $authorizing_phid = $repository->getPHID();
         $lease = DrydockLease::initializeNewLease()->setResourceType($working_copy_type)->setOwnerPHID($operation->getPHID())->setAuthorizingPHID($authorizing_phid)->setAllowedBlueprintPHIDs($allowed_phids);
         $map = $this->buildRepositoryMap($operation);
         $lease->setAttribute('repositories.map', $map);
         $task_id = $this->getCurrentWorkerTaskID();
         if ($task_id) {
             $lease->setAwakenTaskIDs(array($task_id));
         }
         $operation->setProperty('exec.leasePHID', $lease->getPHID())->save();
         $lease->queueForActivation();
     }
     if ($lease->isActivating()) {
         throw new PhabricatorWorkerYieldException(15);
     }
     if (!$lease->isActive()) {
         throw new PhabricatorWorkerPermanentFailureException(pht('Lease "%s" never activated.', $lease->getPHID()));
     }
     return $lease;
 }