Differential D21054 Diff 50163 src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/repository/daemon/PhabricatorRepositoryPullLocalDaemon.php
| Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | protected function run() { | ||||
| $retry_after = array(); | $retry_after = array(); | ||||
| $min_sleep = 15; | $min_sleep = 15; | ||||
| $max_sleep = phutil_units('5 minutes in seconds'); | $max_sleep = phutil_units('5 minutes in seconds'); | ||||
| $max_futures = 4; | $max_futures = 4; | ||||
| $futures = array(); | $futures = array(); | ||||
| $queue = array(); | $queue = array(); | ||||
| $future_pool = new FuturePool(); | |||||
| $future_pool->getIteratorTemplate() | |||||
| ->setUpdateInterval($min_sleep); | |||||
| $sync_wait = phutil_units('2 minutes in seconds'); | $sync_wait = phutil_units('2 minutes in seconds'); | ||||
| $last_sync = array(); | $last_sync = array(); | ||||
| while (!$this->shouldExit()) { | while (!$this->shouldExit()) { | ||||
| PhabricatorCaches::destroyRequestCache(); | PhabricatorCaches::destroyRequestCache(); | ||||
| $device = AlmanacKeys::getLiveDevice(); | $device = AlmanacKeys::getLiveDevice(); | ||||
| $pullable = $this->loadPullableRepositories($include, $exclude, $device); | $pullable = $this->loadPullableRepositories($include, $exclude, $device); | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | while (!$this->shouldExit()) { | ||||
| $display_name = $repository->getDisplayName(); | $display_name = $repository->getDisplayName(); | ||||
| $this->log( | $this->log( | ||||
| pht( | pht( | ||||
| 'Starting update for repository "%s".', | 'Starting update for repository "%s".', | ||||
| $display_name)); | $display_name)); | ||||
| unset($queue[$id]); | unset($queue[$id]); | ||||
| $futures[$id] = $this->buildUpdateFuture( | |||||
| $future = $this->buildUpdateFuture( | |||||
| $repository, | $repository, | ||||
| $no_discovery); | $no_discovery); | ||||
| $futures[$id] = $future->getFutureKey(); | |||||
| $future_pool->addFuture($future); | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if ($queue) { | if ($queue) { | ||||
| $this->log( | $this->log( | ||||
| pht( | pht( | ||||
| 'Not enough process slots to schedule the other %s '. | 'Not enough process slots to schedule the other %s '. | ||||
| 'repository(s) for updates yet.', | 'repository(s) for updates yet.', | ||||
| phutil_count($queue))); | phutil_count($queue))); | ||||
| } | } | ||||
| if ($futures) { | if ($future_pool->hasFutures()) { | ||||
| $iterator = id(new FutureIterator($futures)) | while ($future_pool->hasFutures()) { | ||||
| ->setUpdateInterval($min_sleep); | $future = $future_pool->resolve(); | ||||
| foreach ($iterator as $id => $future) { | |||||
| $this->stillWorking(); | $this->stillWorking(); | ||||
| if ($future === null) { | if ($future === null) { | ||||
| $this->log(pht('Waiting for updates to complete...')); | $this->log(pht('Waiting for updates to complete...')); | ||||
| $this->stillWorking(); | |||||
| if ($this->loadRepositoryUpdateMessages()) { | if ($this->loadRepositoryUpdateMessages()) { | ||||
| $this->log(pht('Interrupted by pending updates!')); | $this->log(pht('Interrupted by pending updates!')); | ||||
| break; | break; | ||||
| } | } | ||||
| continue; | continue; | ||||
| } | } | ||||
| $future_key = $future->getFutureKey(); | |||||
| $repository_id = null; | |||||
| foreach ($futures as $id => $key) { | |||||
| if ($key === $future_key) { | |||||
| $repository_id = $id; | |||||
| unset($futures[$id]); | unset($futures[$id]); | ||||
| $retry_after[$id] = $this->resolveUpdateFuture( | break; | ||||
| $pullable[$id], | } | ||||
| } | |||||
| $retry_after[$repository_id] = $this->resolveUpdateFuture( | |||||
| $pullable[$repository_id], | |||||
| $future, | $future, | ||||
| $min_sleep); | $min_sleep); | ||||
| // We have a free slot now, so go try to fill it. | // We have a free slot now, so go try to fill it. | ||||
| break; | break; | ||||
| } | } | ||||
| // Jump back into prioritization if we had any futures to deal with. | // Jump back into prioritization if we had any futures to deal with. | ||||
| ▲ Show 20 Lines • Show All 333 Lines • Show Last 20 Lines | |||||