Example #1
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  * @Route("/", name="cron")
  */
 public function indexAction(Request $request)
 {
     $this->runtimeWatcher = $this->get('runtimeWatcher');
     $this->runtimeWatcher->setTimeLimit($this->timeLimit);
     $this->importLog = $this->get('importLog');
     for ($i = 0; $i < $this->userLimit; $i++) {
         if (!$this->isInTimeLimit()) {
             $this->importLog->addMessage('reached global time limit');
             break;
         }
         if (!$this->isInFailLimit()) {
             $this->importLog->addMessage('reached global ERROR limit');
             //TODO e-mail küldés
             //valami globális hiba lehet az importban
             //célszerű lehet ilyenkor az összes importot lock-olni
             break;
         }
         $time = new \DateTime();
         $time->sub(new \DateInterval($this->sleepInterval));
         $this->globalEntityManager = $this->getDoctrine()->getManager('global');
         $repository = $this->globalEntityManager->getRepository('AppBundle:ImportScheduleLog');
         $query = $repository->createQueryBuilder('s')->where('s.lastFinishedImportDate < :time')->andWhere('s.failedCounter < :failed')->andWhere('s.isLock = 0')->setParameter('time', $time)->setParameter('failed', $this->failLimitPerUser)->addOrderBy('s.priority', 'DESC')->addOrderBy('s.lastFinishedImportDate', 'ASC')->addOrderBy('s.createDate', 'ASC')->setMaxResults(1)->getQuery();
         $schedules = $query->getResult();
         if (!isset($schedules[0])) {
             break;
         }
         $schedule = $schedules[0];
         $this->runOneUserImports($schedule);
     }
     $this->importLog->addMessage('run finished | ' . $this->importLog->getAllProcessItemCount());
     $this->importLog->setRuntime($this->runtimeWatcher->getRuntime());
     $log = $this->importLog->getGlobalLog();
     $this->globalEntityManager->persist($log);
     $this->globalEntityManager->flush();
     return $this->render('CronBundle::message.html.twig', array('message' => $this->importLog->getMessage()));
 }