public function reserveTask($tube = null)
    {
        if (is_null($tube)) {
            $tube = $this->defaultTube;
        }
        $inTask = $this->beanstalk
            ->watch($tube)
            ->ignore('default')
            ->reserve(2);
        if ($inTask === false) {
            return null;
        }
        $data = $inTask->getData();
        $parts = explode("::", $data, 2);
        if (count($parts) !== 2) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException("Invalid format in TaskQueue {$tube}");
        }
        try {
            $taskObject = $this->serializer->deserialize($parts[1], $parts[0], 'json');
        } catch (UnsupportedFormatException $exception) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException("Invalid format in TaskQueue {$tube} ");
        } catch (\ReflectionException $exception) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException(
                "Invalid format in TaskQueue {$tube} class " . $parts[0] . ' is unknown'
            );
        }
        if (!($taskObject instanceof TaskDescriptionInterface)) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException("Invalid data in TaskQueue {$tube}");
        }
        if (!$this->databaseDisabled) {
            $taskEntity = $this->taskRepo->find($taskObject->getTaskIdentifier());
        } else {
            //remake the task entity
            $taskEntity = new Task($taskObject, '', $tube);
        }
        if (!($taskEntity instanceof Task)) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException(
                "Unable to find taskEntity for task:" . $taskObject->getTaskIdentifier()
            );
        }
        /**
         * @var Task $taskEntity
         */
        $workPackage = new WorkPackage($taskEntity, $inTask, $taskObject);
        $this->updateTaskStatus($workPackage, Task::STATUS_WORKING);
        return $workPackage;
    }
public function reserveTask($tube = null)
    {
        if (is_null($tube)) {
            $tube = $this->defaultTube;
        }
        $inTask = $this->beanstalk
            ->watch($tube)
            ->ignore('default')
            ->reserve(2);
        if ($inTask === false) {
            return null;
        }
        $data = $inTask->getData();
        $parts = explode("::", $data, 2);
        if (count($parts) !== 2) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException("Invalid format in TaskQueue {$tube}");
        }
        try {
            $taskObject = $this->serializer->deserialize($parts[1], $parts[0], 'json');
        } catch (UnsupportedFormatException $exception) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException("Invalid format in TaskQueue {$tube} ");
        } catch (\ReflectionException $exception) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException(
                "Invalid format in TaskQueue {$tube} class " . $parts[0] . ' is unknown'
            );
        }
        if (!($taskObject instanceof TaskDescriptionInterface)) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException("Invalid data in TaskQueue {$tube}");
        }
        if (!$this->databaseDisabled) {
            $taskEntity = $this->taskRepo->find($taskObject->getTaskIdentifier());
        } else {
            //remake the task entity
            $taskEntity = new Task($taskObject, '', $tube);
        }
        if (!($taskEntity instanceof Task)) {
            $this->beanstalk->delete($inTask);
            throw new TaskQueueServiceException(
                "Unable to find taskEntity for task:" . $taskObject->getTaskIdentifier()
            );
        }
        /**
         * @var Task $taskEntity
         */
        $workPackage = new WorkPackage($taskEntity, $inTask, $taskObject);
        $this->updateTaskStatus($workPackage, Task::STATUS_WORKING);
        return $workPackage;
    }
public function reserveTask ( $ tube = null ) { if ( is_null ( $ tube ) ) { $ tube = $ this -> defaultTube ; } $ inTask = $ this -> beanstalk -> watch ( $ tube ) -> ignore ( 'default' ) -> reserve ( 2 ) ; if ( $ inTask === false ) { return null ; } $ data = $ inTask -> getData ( ) ; $ parts = explode ( "::" , $ data , 2 ) ; if ( count ( $ parts ) !== 2 ) { $ this -> beanstalk -> delete ( $ inTask ) ; throw new TaskQueueServiceException ( "Invalid format in TaskQueue {$tube}" ) ; } try { $ taskObject = $ this -> serializer -> deserialize ( $ parts [ 1 ] , $ parts [ 0 ] , 'json' ) ; } catch ( UnsupportedFormatException $ exception ) { $ this -> beanstalk -> delete ( $ inTask ) ; throw new TaskQueueServiceException ( "Invalid format in TaskQueue {$tube} " ) ; } catch ( \ ReflectionException $ exception ) { $ this -> beanstalk -> delete ( $ inTask ) ; throw new TaskQueueServiceException ( "Invalid format in TaskQueue {$tube} class " . $ parts [ 0 ] . ' is unknown' ) ; } if ( ! ( $ taskObject instanceof TaskDescriptionInterface ) ) { $ this -> beanstalk -> delete ( $ inTask ) ; throw new TaskQueueServiceException ( "Invalid data in TaskQueue {$tube}" ) ; } if ( ! $ this -> databaseDisabled ) { $ taskEntity = $ this -> taskRepo -> find ( $ taskObject -> getTaskIdentifier ( ) ) ; } else { //remake the task entity $ taskEntity = new Task ( $ taskObject , '' , $ tube ) ; } if ( ! ( $ taskEntity instanceof Task ) ) { $ this -> beanstalk -> delete ( $ inTask ) ; throw new TaskQueueServiceException ( "Unable to find taskEntity for task:" . $ taskObject -> getTaskIdentifier ( ) ) ; } /**
         * @var Task $taskEntity
         */ $ workPackage = new WorkPackage ( $ taskEntity , $ inTask , $ taskObject ) ; $ this -> updateTaskStatus ( $ workPackage , Task :: STATUS_WORKING ) ; return $ workPackage ; }
Returns a task to work on.

@param string $tube (optional) the tube(queue) to reserve a task from

@throws TaskQueueServiceException
@return WorkPackage
Returns a task to work on .