private function changeState(Cron $cron, $state, $lastError = null)
    {
        $cron->setState($state);
        $cron->setLastError($lastError);

        $em = $this->getEntityManager();
        $em->persist($cron);
        $em->flush($cron);
    }