<?php
/**
* @author OfficeBrain 4160 <info@officebrain.com>
*
* Description : Run Transaction Queue Command to read from queue of MongoDB and execute action
*
**/
namespace OfficeBrain\Bundle\QueueBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;

class RunTransactionQueueCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('office_brain_queue:transaction:run')
            ->addArgument('instance_id', InputArgument::REQUIRED, 'Instance is of Supplier | Distributor', null)
            ->addArgument('count', InputArgument::REQUIRED, 'Count of Jobs to execute in batch', null)
            ->setDescription('Start up Transaction Queue');
    }

    /**
    * @author Employee Id: 4160
    * Description :
    * Execute command to run transaction queue
    *
    * @return type
    *
    **/
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $instance_id = $input->getArgument('instance_id');
        $count = $input->getArgument('count');
        
        $GLOBALS['instanceId'] = $instance_id;
        
        
        $event = new GetResponseEvent($this->getContainer()->get('kernel'),  $this->getContainer()->get('request'), HttpKernelInterface::MASTER_REQUEST);
        $container = $this->getContainer();
        $request = $container->get('request');
        $request->attributes->set('runQueue', 'TransactionQueueExtended');
        
        $queueApiManager = $container->get('office_brain_queue_api_manager');
        
        $when = new \DateTime();
        $batch = true;
        $priority = 1;
        $queueApiManager->processRunQueue($instance_id, $count);
        echo "Run transaction queue successfully...";
        die;
    }
}
