protected function execute(InputInterface $input, OutputInterface $output) { $i = 0; $kernel = $this->getContainer()->get('kernel'); $doctrine = $this->getContainer()->get('doctrine'); $entityManager = $doctrine->getEntityManager(); $cron = new Cron(); $cron->setTimestamp(time()); $cron->setAction('Observe Alarms Start'); $entityManager->persist($cron); $entityManager->flush(); $isSandbox = $input->getOption('sandbox'); $isEmulation = $input->getOption('emulate'); $output->writeln('Sandbox: ' . $isSandbox); $output->writeln('Emulation: ' . $isEmulation); // operating under the assumption that this thing is executed by a cronjob, this thing needs to be run for just a minute $intervalSpent = 0; while ($intervalSpent <= self::CRON_INTERVAL) { $detector = new AlarmDetector($doctrine); $detector->detectAlarms($isEmulation); $output->writeln(PHP_EOL . ++$i . PHP_EOL); usleep(self::CHECK_INTERVAL); // 250ms $intervalSpent += self::CHECK_INTERVAL; } }
/** * @Route("/alarms/detect", name="homepage") */ public function detectAlarmsAction() { $doctrine = $this->getDoctrine(); $detector = new AlarmDetector($doctrine); $detector->detectAlarms(); // $alertLocator = new AlertLocator(); return new Response(); // return $this->render('default/index.html.twig'); }