Catch mySqlGoneAway error from originated from MailPoet crons

MAILPOET-6020
This commit is contained in:
Oluwaseun Olorunsola
2024-05-24 00:01:18 +01:00
committed by Aschepikov
parent 988dec3e66
commit 81f29a61ac
4 changed files with 35 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
namespace MailPoet\Cron\ActionScheduler; namespace MailPoet\Cron\ActionScheduler;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class RemoteExecutorHandler { class RemoteExecutorHandler {
@@ -41,9 +42,17 @@ class RemoteExecutorHandler {
} }
public function runActionScheduler(): void { public function runActionScheduler(): void {
$this->wp->addFilter('action_scheduler_queue_runner_concurrent_batches', [$this, 'ensureConcurrency']); try {
\ActionScheduler_QueueRunner::instance()->run(); $this->wp->addFilter('action_scheduler_queue_runner_concurrent_batches', [$this, 'ensureConcurrency']);
wp_die(); \ActionScheduler_QueueRunner::instance()->run();
wp_die();
} catch (\Exception $e) {
$mySqlGoneAwayMessage = Helpers::mySqlGoneAwayExceptionHandler($e);
if ($mySqlGoneAwayMessage) {
throw new \Exception($mySqlGoneAwayMessage, 0, $e);
}
throw $e;
}
} }
/** /**

View File

@@ -4,6 +4,7 @@ namespace MailPoet\Cron;
use MailPoet\Cron\Triggers\WordPress; use MailPoet\Cron\Triggers\WordPress;
use MailPoet\Settings\SettingsController; use MailPoet\Settings\SettingsController;
use MailPoet\Util\Helpers;
class CronTrigger { class CronTrigger {
const METHOD_LINUX_CRON = 'Linux Cron'; const METHOD_LINUX_CRON = 'Linux Cron';
@@ -51,6 +52,7 @@ class CronTrigger {
return false; return false;
} catch (\Exception $e) { } catch (\Exception $e) {
// cron exceptions should not prevent the rest of the site from loading // cron exceptions should not prevent the rest of the site from loading
Helpers::mySqlGoneAwayExceptionHandler($e);
} }
} }

View File

@@ -4,6 +4,7 @@ namespace MailPoet\Cron;
use MailPoet\Cron\Workers\WorkersFactory; use MailPoet\Cron\Workers\WorkersFactory;
use MailPoet\Logging\LoggerFactory; use MailPoet\Logging\LoggerFactory;
use MailPoet\Util\Helpers;
use MailPoetVendor\Doctrine\ORM\EntityManager; use MailPoetVendor\Doctrine\ORM\EntityManager;
class Daemon { class Daemon {
@@ -61,6 +62,8 @@ class Daemon {
$worker->process($this->timer); // BC for workers not implementing CronWorkerInterface $worker->process($this->timer); // BC for workers not implementing CronWorkerInterface
} }
} catch (\Exception $e) { } catch (\Exception $e) {
Helpers::mySqlGoneAwayExceptionHandler($e);
$workerClassNameParts = explode('\\', get_class($worker)); $workerClassNameParts = explode('\\', get_class($worker));
$workerName = end($workerClassNameParts); $workerName = end($workerClassNameParts);
$errors[] = [ $errors[] = [

View File

@@ -18,6 +18,7 @@ use MailPoet\Mailer\MailerLog;
use MailPoet\Newsletter\Sending\ScheduledTasksRepository; use MailPoet\Newsletter\Sending\ScheduledTasksRepository;
use MailPoet\Services\Bridge; use MailPoet\Services\Bridge;
use MailPoet\Settings\SettingsController; use MailPoet\Settings\SettingsController;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
use MailPoetVendor\Doctrine\ORM\EntityManager; use MailPoetVendor\Doctrine\ORM\EntityManager;
@@ -70,16 +71,24 @@ class WordPress {
} }
public function run() { public function run() {
if (!$this->checkRunInterval()) { try {
return false; if (!$this->checkRunInterval()) {
} return false;
if (!$this->checkExecutionRequirements()) { }
$this->stop(); if (!$this->checkExecutionRequirements()) {
return; $this->stop();
} return;
}
$this->supervisor->init(); $this->supervisor->init();
return $this->supervisor->checkDaemon(); return $this->supervisor->checkDaemon();
} catch (\Exception $e) {
$mySqlGoneAwayMessage = Helpers::mySqlGoneAwayExceptionHandler($e);
if ($mySqlGoneAwayMessage) {
throw new \Exception($mySqlGoneAwayMessage, 0, $e);
}
throw $e;
}
} }
private function checkRunInterval(): bool { private function checkRunInterval(): bool {