protected function executeJobs()
    {
        // Get the Jobs to be processed.
        $jobsInQueue = $this->em
            ->getRepository('CampaignChainCoreBundle:Job')
            ->getOpenJobsForScheduler($this->scheduler);

        if (empty($jobsInQueue)) {
            return;
        }

        $this->io->section('Executing jobs now:');
        $this->logger->info('Executing {counter} jobs now:', ['counter' => count($jobsInQueue)]);
        $this->io->progressStart(count($jobsInQueue));

        foreach ($jobsInQueue as $jobInQueue) {
            // Execute job.
            $this->executeJob($jobInQueue);

            $this->io->progressAdvance();
        }

        // ensure that the progress bar is at 100%
        $this->io->progressFinish();

        $this->em->clear();
        // Get the processed jobs.
        $jobsProcessed = $this->em
            ->getRepository('CampaignChainCoreBundle:Job')
            ->getProcessedJobsForScheduler($this->scheduler);

        if (empty($jobsProcessed)) {
            return;
        }

        // Display the results of the execution.

        $tableHeader = [
            'Job ID',
            'Operation ID',
            'Process ID',
            'Job Name',
            'Job Start Date',
            'Job End Date',
            'Duration',
            'Status',
            'Message',
        ];
        $outputTableRows = [];

        foreach ($jobsProcessed as $jobProcessed) {
            $startDate = null;
            $endDate = null;

            if ($jobProcessed->getStartDate()) {
                $startDate = $jobProcessed->getStartDate()->format('Y-m-d H:i:s');
            }
            if ($jobProcessed->getEndDate()) {
                $endDate = $jobProcessed->getEndDate()->format('Y-m-d H:i:s');
            }

            $jobData = [
                $jobProcessed->getId(),
                $jobProcessed->getActionId(),
                $jobProcessed->getPid(),
                $jobProcessed->getName(),
                $startDate,
                $endDate,
                $jobProcessed->getDuration().' ms',
                $jobProcessed->getStatus(),
                $jobProcessed->getMessage(),
            ];

            $outputTableRows[] = $jobData;

            if (Job::STATUS_ERROR === $jobProcessed->getStatus()) {
                $context = array_combine($tableHeader, $jobData);
                $this->logger->error($jobProcessed->getMessage(), $context);
            }
        }

        $this->io->text('Results of executed actions:');
        $this->io->table($tableHeader, $outputTableRows);
    }