Exemple #1
0
 protected function buildResults()
 {
     $this->logDebug("Building result objects...\n");
     $countStatus = new CountStatus();
     $countStatus->setTotal(count($this->operations));
     $statusPrinter = new StatusPrinter($countStatus);
     $i = 0;
     /** @var Operation $operation */
     foreach ($this->operations as $k => $operation) {
         $result = new OperationResult($operation);
         $result->copyLogger($this);
         $this->queue[$operation->getId()] = $result;
         $countStatus->completed(1);
         if (++$i % 10000 == 0) {
             $statusPrinter->printStatus();
         }
     }
     $statusPrinter->finish();
     $this->result->setQueue($this->queue);
     $this->queueBuilt = true;
     $this->logDebug("Finished building result objects...\n");
 }
Exemple #2
0
 public function run()
 {
     $this->operations = $this->buildOperations();
     $this->targetOperationLists = $this->buildTargetRunners();
     $statuses = array();
     /** @var OperationList $list */
     foreach ($this->targetOperationLists as $list) {
         $statuses[] = $list->getResult()->getStatus();
     }
     $statusPrinter = new StatusPrinter(new AggregateStatus($statuses));
     $this->logInfo("Starting to execute queued operations...");
     for ($r = 0; $r < self::BATCH_RETRY_LIMIT; $r++) {
         $httpRunner = new HttpRunner($this->targetOperationLists);
         $httpRunner->copyLogger($this);
         $httpRunner->setStatusCallback(array($statusPrinter, 'printStatus'));
         $httpRunner->run();
         $failedCount = $this->getFailedCount();
         if ($failedCount == 0) {
             break;
         }
         if ($r < self::BATCH_RETRY_LIMIT - 1) {
             $this->logError(sprintf("%d operations failed in last batch, retrying(%d)...", $failedCount, $r));
             sleep(10);
             /** @var OperationList $list */
             foreach ($this->targetOperationLists as $list) {
                 $list->retry();
             }
         }
     }
     $statusPrinter->finish();
 }