@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

While waiting for a "bin/drydock" lease to activate, entertain the user with log output

Summary: Depends on D19071. Ref T13073. While the daemons are supposedly doing things, show the user any logs they generate. There's often something relevant but unearthing it can be involved.

Test Plan: {F5427773}

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13073

Differential Revision: https://secure.phabricator.com/D19072

+77 -33
+77 -1
src/applications/drydock/management/DrydockManagementLeaseWorkflow.php
··· 90 90 "%s\n", 91 91 pht('Waiting for daemons to activate lease...')); 92 92 93 - $lease->waitUntilActive(); 93 + $this->waitUntilActive($lease); 94 94 95 95 echo tsprintf( 96 96 "%s\n", 97 97 pht('Activated lease "%s".', $lease->getID())); 98 98 99 99 return 0; 100 + } 101 + 102 + 103 + private function waitUntilActive(DrydockLease $lease) { 104 + $viewer = $this->getViewer(); 105 + 106 + $log_cursor = 0; 107 + $log_types = DrydockLogType::getAllLogTypes(); 108 + 109 + $is_active = false; 110 + while (!$is_active) { 111 + $lease->reload(); 112 + 113 + // While we're waiting, show the user any logs which the daemons have 114 + // generated to give them some clue about what's going on. 115 + $logs = id(new DrydockLogQuery()) 116 + ->setViewer($viewer) 117 + ->withLeasePHIDs(array($lease->getPHID())) 118 + ->setBeforeID($log_cursor) 119 + ->execute(); 120 + if ($logs) { 121 + $logs = mpull($logs, null, 'getID'); 122 + ksort($logs); 123 + $log_cursor = last_key($logs); 124 + } 125 + 126 + foreach ($logs as $log) { 127 + $type_key = $log->getType(); 128 + if (isset($log_types[$type_key])) { 129 + $type_object = id(clone $log_types[$type_key]) 130 + ->setLog($log) 131 + ->setViewer($viewer); 132 + 133 + $log_data = $log->getData(); 134 + 135 + $type = $type_object->getLogTypeName(); 136 + $data = $type_object->renderLog($log_data); 137 + } else { 138 + $type = pht('Unknown ("%s")', $type_key); 139 + $data = null; 140 + } 141 + 142 + echo tsprintf( 143 + "<%s> %B\n", 144 + $type, 145 + $data); 146 + } 147 + 148 + $status = $lease->getStatus(); 149 + 150 + switch ($status) { 151 + case DrydockLeaseStatus::STATUS_ACTIVE: 152 + $is_active = true; 153 + break; 154 + case DrydockLeaseStatus::STATUS_RELEASED: 155 + throw new Exception(pht('Lease has already been released!')); 156 + case DrydockLeaseStatus::STATUS_DESTROYED: 157 + throw new Exception(pht('Lease has already been destroyed!')); 158 + case DrydockLeaseStatus::STATUS_BROKEN: 159 + throw new Exception(pht('Lease has been broken!')); 160 + case DrydockLeaseStatus::STATUS_PENDING: 161 + case DrydockLeaseStatus::STATUS_ACQUIRED: 162 + break; 163 + default: 164 + throw new Exception( 165 + pht( 166 + 'Lease has unknown status "%s".', 167 + $status)); 168 + } 169 + 170 + if ($is_active) { 171 + break; 172 + } else { 173 + sleep(1); 174 + } 175 + } 100 176 } 101 177 102 178 }
-32
src/applications/drydock/storage/DrydockLease.php
··· 194 194 return false; 195 195 } 196 196 197 - public function waitUntilActive() { 198 - while (true) { 199 - $lease = $this->reload(); 200 - if (!$lease) { 201 - throw new Exception(pht('Failed to reload lease.')); 202 - } 203 - 204 - $status = $lease->getStatus(); 205 - 206 - switch ($status) { 207 - case DrydockLeaseStatus::STATUS_ACTIVE: 208 - return; 209 - case DrydockLeaseStatus::STATUS_RELEASED: 210 - throw new Exception(pht('Lease has already been released!')); 211 - case DrydockLeaseStatus::STATUS_DESTROYED: 212 - throw new Exception(pht('Lease has already been destroyed!')); 213 - case DrydockLeaseStatus::STATUS_BROKEN: 214 - throw new Exception(pht('Lease has been broken!')); 215 - case DrydockLeaseStatus::STATUS_PENDING: 216 - case DrydockLeaseStatus::STATUS_ACQUIRED: 217 - break; 218 - default: 219 - throw new Exception( 220 - pht( 221 - 'Lease has unknown status "%s".', 222 - $status)); 223 - } 224 - 225 - sleep(1); 226 - } 227 - } 228 - 229 197 public function setActivateWhenAcquired($activate) { 230 198 $this->activateWhenAcquired = true; 231 199 return $this;