This topic contains 2 replies, has 2 voices, and was last updated by shreyas 7 years, 3 months ago.
- Topic
Hi Team,
I have written a Custom Command Class that contains tasks that has to be executed(DB related tasks) for certain amount of time that would be given in getDefaultDefinition(). Now when i set the cron, it behaves unexpected . At some times it Runs perfectly as expected But every alternative or so i get some wierd error as given below in screenshot:
And Sometimes it works perfectly fine as in given below screenshot:
The alternative Passes & fail of Cron Command Summary is given in below Screenshot:
The Common error we get here for Fail state(As shown in screenshot above is) as: [InvalidArgumentException]
Command “oro:cron:taskdelayevent-email” is not defined.I even thought is it due to some tasks written in execute() that is causing some exception & command fails but that is not the issue since when i run this manually in app/console it perfectly works as expected.
i.e:
When i run this command any time manually as shown above , i do not get any exception.So i guess it is not from code written in this Execute() function. I am stuck on how to get over with this issue as it is necessary to be working as Automated & i cannot manually enter the command & run every now & then. i have followed similar way as other code i had written which is perfectly working fine without any issues except some logic changes in Execute() function & use of Repository here.
Please find the code snippet of Code used in Custom Bundle (CustomTaskBundle/Command) :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145<?phpnamespace Custom\Bundle\TaskBundle\Command;use Symfony\Component\Console\Input\InputOption;use Symfony\Component\Console\Input\InputInterface;use Symfony\Component\Console\Output\OutputInterface;use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;use Oro\Bundle\CronBundle\Command\CronCommandInterface;use Custom\Bundle\OroBundle\Entity\TaskReminder;class TaskDelayEventEmailCommand extends ContainerAwareCommand implements CronCommandInterface {const COMMAND_NAME = 'oro:cron:taskdelayevent-email';public function getTaskRepository() {return $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository("OroCRMTaskBundle:Task");}/*** {@inheritdoc}*/public function getDefaultDefinition() {$defaultTimeSet = $this->getTaskRepository()->getConfigValueWithNoBusinessUnitOrganization('TASK_DELAY_TIME_SETTER');if (empty($defaultTimeSet) == FALSE) {$timer = $defaultTimeSet;} else {$timer = '* * * * *';}return $timer;}/*** {@inheritdoc}*/public function configure() {$this->setName(self::COMMAND_NAME);$this->setDescription('This Command provides Reminder mail to Users involved in appointment prior to the meeting');$this->addOption('force', 'f', InputOption::VALUE_NONE, 'This option enforces in triggering mails that meet conditions defined');$this->addOption('use-delete', null, InputOption::VALUE_NONE, 'This option enforces to use DELETE statement instead TRUNCATE for force mode');}public function saveTaskReminder($taskEntity, $businessUnitId, $reminderStatus, $organizationId) {$entityManager = $this->getContainer()->get('doctrine.orm.entity_manager');$taskReminder = new TaskReminder();$taskReminder->setTaskId($taskEntity);$businessUnit = $entityManager->getRepository('Oro\Bundle\OrganizationBundle\Entity\BusinessUnit')->find($businessUnitId);$taskReminder->setBusinessUnit($businessUnit);$taskReminder->setReminderStatus($reminderStatus);$organization = $entityManager->getRepository('Oro\Bundle\OrganizationBundle\Entity\Organization')->find($organizationId);$taskReminder->setOrganization($organization);$entityManager->persist($taskReminder);$entityManager->flush();return true;}/*** {@inheritdoc}*/public function execute(InputInterface $input, OutputInterface $output) {$logger = $this->getContainer()->get('logger');$em = $this->getContainer()->get('doctrine.orm.entity_manager');$configs = array();$organizationsArray = $this->getTaskRepository()->getOrganizations();$processor = $this->getContainer()->get('custom_mail.processor');foreach ($organizationsArray as $organizations) {$orgId = $organizations['id'];$businessUnitsResult = $this->getTaskRepository()->getBusinessUnitsForOrganization($orgId);foreach ($businessUnitsResult as $buidsArray) {$buId = $buidsArray['id'];$output->writeln("<info>Inside bu id $buId </info>");$businessUnitOrganization = "buId" . $buId . "orgId" . $orgId;$senderEmail = $this->getTaskRepository()->getConfigValue('SENDER_EMAIL', $buId, $orgId);if (empty($senderEmail) == FALSE) {// check for sender email blank or not//NUM_OF_INTERNAL_ESCALATION$noOfInternalEscalations = $this->getTaskRepository()->getConfigValueWithNoBusinessUnitOrganization('NUM_OF_INTERNAL_ESCALATION');for ($i = 1; $i <= $noOfInternalEscalations; $i++) { // INTERNAL Tasks$configLabelForTime = 'Internal_Task_Escalation_Time' . $i;$configLabelForTemplate = 'Internal_Task_Escalation_Template' . $i;$configflag = 'Internal_Task_Escalation' . $i;$configs[$businessUnitOrganization][$configLabelForTime] = $this->getTaskRepository()->getConfigValue($configLabelForTime, $buId, $orgId);if ((empty($configs[$businessUnitOrganization][$configLabelForTime])) == FALSE) {$configs[$businessUnitOrganization][$configLabelForTemplate] = $this->getTaskRepository()->getConfigValue($configLabelForTemplate, $buId, $orgId);$resultSet = $this->getTaskRepository()->getTasksExpired($configs[$businessUnitOrganization][$configLabelForTime], $buId, $configflag, $orgId);if ((empty($resultSet) == FALSE) && (empty($configs[$businessUnitOrganization][$configLabelForTemplate]) == FALSE)) {foreach ($resultSet as $tasks) {$taskId = $tasks['id'];$ownerId = $tasks['owner_id'];$taskEntity = $em->find('OroCRM\Bundle\TaskBundle\Entity\Task', $taskId);$usrEntity = $em->find('Oro\Bundle\UserBundle\Entity\User', $ownerId);$usrEmail = $usrEntity->getEmail();$sentmailsuccess = 0;$sentmailsuccess = $processor->getEmailTemplateAndSendEmail($usrEmail, $senderEmail, $configs[$businessUnitOrganization][$configLabelForTemplate], ['entity' => $taskEntity], $usrEntity);if ($sentmailsuccess) {if (!($this->saveTaskReminder($taskEntity, $buId, $configflag, $orgId))) {$output->writeln("<info>error in adding reminder for user to task with id $taskId </info>");}$output->writeln("<info>sent mail to usr $usrEmail </info>");} else {$output->writeln("<info>Error in sending mail to usr $usrEmail </info>");}}}}// close - presence of $configLabelForTime}//for Internal Task loop end}//SENDER EMAIL Not empty Endelse {$output->writeln("<info>Sender Email not defined Inside bu - $buId for organization $orgId </info>");}} // end of Business Unit Id Loops}//end of Organizations}/*** @param string $id** @return object*/protected function getService($id) {return $this->getContainer()->get($id);}}Pleas need help in how to solve this issue so that cron command would run correctly at regular interval of time specified in getDefaultDefinition() function.
Thanks & Regards,
Shreyas S
The forum ‘OroCRM’ is closed to new topics and replies.