MGDigital\BusQue\QueueWorker::work PHP Метод

work() публичный Метод

public work ( string $queueName, integer $n = null, integer $time = null )
$queueName string
$n integer
$time integer
    public function work(string $queueName, int $n = null, int $time = null)
    {
        $stopwatchStart = time();
        while ($n === null || $n > 0) {
            try {
                $this->iterate($queueName, $time);
                $n === null || $n--;
            } catch (DriverException $exception) {
                $this->implementation->getLogger()->error($exception->getMessage(), compact('exception'));
            } catch (ConcurrencyException $exception) {
                // do nothing
            } catch (TimeoutException $exception) {
                break;
            }
            if ($time !== null && time() - $stopwatchStart >= $time) {
                break;
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * @When I run the queue worker
  */
 public function iRunTheQueueWorker()
 {
     $worker = new QueueWorker($this->implementation);
     try {
         $worker->work('test_queue', 1, 1);
     } catch (TimeoutException $e) {
     }
 }