Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueueCollection does not iterate #7

Closed
clicktrend opened this issue Mar 15, 2017 · 1 comment
Closed

QueueCollection does not iterate #7

clicktrend opened this issue Mar 15, 2017 · 1 comment

Comments

@clicktrend
Copy link
Contributor

clicktrend commented Mar 15, 2017

The process in EntityQueueManagement.php stops with limit of batch size without iteration through the queue.

This code loads queue fully with setting current page for collection

/**
     * {@inheritdoc}
     * @return $this
     */
    protected function getQueueCollection($curPage = 1)
    {
        $entityQueueCollection = $this->entityQueueFactory->create()->getCollection();
        $entityQueueCollection->addFilter('processed', ['eq' => 0]);
        return $entityQueueCollection->setPageSize($this->getBatchSize())->setCurPage($curPage);
    }

    /**
     * {@inheritdoc}
     * @return bool
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function processQueue()
    {
        $allLoaded = FALSE;
        $curPage = 1;
        $i = 1;
                    
        while(!$allLoaded) {
            $collection = $this->getQueueCollection($curPage);

            if($collection->getSize() >= $i) {
                try {
                    foreach ($collection as $queueItem) {
                        $eventType = $queueItem->getEventType();
                        $processor = null;
                        if ($eventType) {
                            $processor = $this->getEntityProcessor($eventType);
                        }
                        $entityData = $this->getEntityData($queueItem);
                        $result = $processor->process($entityData);
                        var_dump($result);
                        if ($result) {
                            $queueItem->setProcessed(1);
                            $queueItem->setProcessedAt(new \DateTime('now'));
                            $this->entityQueueRepository->save($queueItem);
                        }
                        $i++;
                    }
                } catch (\Exception $e) {
                    throw new \Magento\Framework\Exception\LocalizedException(__('Could not process Queue item'));
                    return false;
                }

                $curPage++;
            } else {
                $allLoaded = TRUE;
            }
        }
        
        return true;
    }
@24198
Copy link
Contributor

24198 commented May 5, 2017

Hi @clicktrend,

The suggested solution has been merged into master.

Kind Regards,

Jaimy Casteleijn

@24198 24198 closed this as completed May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants