StackFormation\Poller::poll PHP Method

poll() public static method

public static poll ( $callback, $pollInterval = 10, $maxPolls = 50 )
    public static function poll($callback, $pollInterval = 10, $maxPolls = 50)
    {
        $first = true;
        do {
            if ($maxPolls-- < 0) {
                throw new \Exception('Max polls exceeded.');
            }
            if ($first) {
                $first = false;
            } else {
                sleep($pollInterval);
            }
            $result = $callback();
        } while (!$result);
        return $result;
    }

Usage Example

Example #1
0
 public function observeStackActivity($pollInterval = 20)
 {
     $eventTable = new StackEventsTable($this->output);
     $lastStatus = Poller::poll(function () use($eventTable) {
         try {
             try {
                 $this->stack = $this->stackFactory->getStack($this->stack->getName(), true);
                 // load fresh instance for updated status
                 $this->output->writeln("-> Polling... (Stack Status: {$this->stack->getStatus()})");
                 $eventTable->renderEvents($this->stack->getEvents());
             } catch (CloudFormationException $exception) {
                 throw Exception::refineException($exception);
             }
         } catch (StackNotFoundException $exception) {
             $this->output->writeln("-> Stack gone.");
             return Stack::STATUS_STACK_GONE;
             // this is != false and will stop the poller
         }
         return $this->stack->isInProgress() ? false : $this->stack->getStatus();
     }, $pollInterval, 1000);
     $this->printStatus($lastStatus);
     $this->printResources();
     $this->printOutputs();
     return $lastStatus;
 }
All Usage Examples Of StackFormation\Poller::poll
Poller