Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : Imap SSL read issue with parellel CronJob execution #56

Open
sreekuttan-m-achari opened this issue Jun 17, 2017 · 0 comments
Open

Comments

@sreekuttan-m-achari
Copy link

Hi , We were having the following issue while running email processing cronjob

`

[Diamante\EmailProcessingBundle\Model\MessageProcessingException]
cannot read - connection closed?

Exception trace:
() at /var/www/html/desk-application/vendor/diamante/email-processing-bundle/Diamante/EmailProcessingBundle/Infrastructure/Message/Zend/ImapMessageProvider.php:85
Diamante\EmailProcessingBundle\Infrastructure\Message\Zend\ImapMessageProvider->fetchMessagesToProcess() at /var/www/html/desk-application/vendor/diamante/email-processing-bundle/Diamante/EmailProcessingBundle/Model/Service/MessageProcessingManager.php:56
Diamante\EmailProcessingBundle\Model\Service\MessageProcessingManager->handle() at /var/www/html/desk-application/vendor/diamante/email-processing-bundle/Diamante/EmailProcessingBundle/Api/Impl/EmailProcessingServiceImpl.php:67
Diamante\EmailProcessingBundle\Api\Impl\EmailProcessingServiceImpl->process() at /var/www/html/desk-application/vendor/diamante/email-processing-bundle/Diamante/EmailProcessingBundle/Command/GeneralEmailProcessingCommand.php:32
Diamante\EmailProcessingBundle\Command\GeneralEmailProcessingCommand->execute() at /var/www/html/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:256
Symfony\Component\Console\Command\Command->run() at /var/www/html/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:846
Symfony\Component\Console\Application->doRunCommand() at /var/www/html/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:189
Symfony\Component\Console\Application->doRun() at /var/www/html/desk-application/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/html/desk-application/vendor/jms/job-queue-bundle/JMS/JobQueueBundle/Console/Application.php:45
JMS\JobQueueBundle\Console\Application->doRun() at /var/www/html/desk-application/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:120
Symfony\Component\Console\Application->run() at /var/www/html/desk-application/app/console:23

`

The cron was getting initiated every 5 minutes while the existing email processing was on going. So we created a file based locking mechanism to prevent this parallel execution.

File location :: "/vendor/diamante/email-processing-bundle/Diamante/EmailProcessingBundle/Command/GeneralEmailProcessingCommand.php "

Modification :

` protected function execute(InputInterface $input, OutputInterface $output) {

	//$flagFile = 'cronFlg.flg';

	$flagFile = dirname(__FILE__).'/cronFlg.flg';

	$output->writeln("Flag-File: ".$flagFile." :  ".date("Y-m-d h:i:sa"));

	if (!file_exists($flagFile)) {
		if (file_put_contents($flagFile, "COMPLETED")) {
			$output->writeln("Flag-File Created : ".date("Y-m-d h:i:sa"));
		} else {
			$output->writeln("Error! Unable to create Flag-File Please check folder/file permissions: ".date("Y-m-d h:i:sa"));
		}
	} else {

		$flg = file_get_contents($flagFile);

		if ($flg == 'COMPLETED') {
			file_put_contents($flagFile, "START");

			$output->writeln("Start General Email Processing : ".date("Y-m-d h:i:sa"));
			$this->getContainer()->get('diamante.email_processing.service')->process();
			$output->writeln("General Email Processing Done : ".date("Y-m-d h:i:sa"));

			file_put_contents($flagFile, "COMPLETED");
		} else {
			$output->writeln("Processing Emails... : ".date("Y-m-d h:i:sa"));
		}
	}

} `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant