MGDigital\BusQue\SchedulerWorker::work PHP Method

work() public method

public work ( integer $limit = null, integer $throttle = self::DEFAULT_THROTTLE, integer $time = null, integer $uSleepTime = 5000000, DateInterval $expiry = null )
$limit integer The maximum number of scheduled commands to queue.
$throttle integer The maximum number of scheduled commands to receive at a time.
$time integer The maximum amount of time in seconds to work.
$uSleepTime integer The number of microseconds to usleep between each query to the scheduler.
$expiry DateInterval The expiry interval for an overdue unqueued command.
    public function work(int $limit = null, int $throttle = self::DEFAULT_THROTTLE, int $time = null, int $uSleepTime = 5000000, \DateInterval $expiry = null)
    {
        $stopwatchStart = time();
        while ($limit === null || $limit > 0) {
            $queuedCount = $this->iterate($throttle, $expiry);
            if ($limit !== null) {
                $limit -= $queuedCount;
                if ($limit <= 0) {
                    break;
                }
            }
            if ($time !== null && time() - $stopwatchStart >= $time) {
                break;
            }
            usleep($uSleepTime);
        }
    }

Usage Example

Example #1
0
 /**
  * @When I run the scheduler worker
  */
 public function iRunTheSchedulerWorker()
 {
     $worker = new SchedulerWorker($this->implementation);
     try {
         $worker->work(null, 100, 0);
     } catch (TimeoutException $e) {
     }
 }