protected function execute(InputInterface $input, OutputInterface $output)
 {
     $storeUrl = $this->getContainer()->getParameter('store_url');
     $client = new Client();
     $dm = $this->getContainer()->get('doctrine_mongodb')->getManager();
     $i = 0;
     while (true) {
         try {
             $response = $client->get($storeUrl . '/queue/pop');
         } catch (\Exception $ex) {
             break;
         }
         if ($response->getStatusCode() != 200) {
             break;
         }
         $response = json_decode($response->getBody());
         $stockRequest = new StockRequest();
         $stockRequest->setTitle($response->title);
         $stockRequest->setQuantity($response->quantity);
         $dm->persist($stockRequest);
         $i++;
     }
     $dm->flush();
     $output->writeln($i . ' new orders added');
 }
 /**
  * @Route("/request", name="request-stock", methods={"POST"})
  * @param Request $request
  * @return JsonResponse
  */
 public function requestAction(Request $request)
 {
     $title = $request->get('title', null);
     $quantity = $request->get('quantity', null);
     if ($title == null || $quantity == null) {
         return $this->fail('"title" and "quantity" (GET) parameters are required.');
     }
     $stockRequest = new StockRequest();
     $stockRequest->setTitle($title);
     $stockRequest->setQuantity($quantity);
     $dm = $this->get('doctrine_mongodb')->getManager();
     $dm->persist($stockRequest);
     $dm->flush();
     return $this->success();
 }