Use CronHelper service in cron workers [MAILPOET-2459]

This commit is contained in:
wxa
2019-10-30 16:26:38 +03:00
committed by Jack Kitterhing
parent 3436fed6e7
commit 81caa04479
14 changed files with 131 additions and 60 deletions

View File

@ -132,7 +132,7 @@ class Migration extends SimpleWorker {
if (!empty($queues)) {
foreach (array_chunk($queues, self::BATCH_SIZE) as $queue_batch) {
// abort if execution limit is reached
CronHelper::enforceExecutionLimit($this->timer);
$this->cron_helper->enforceExecutionLimit($this->timer);
foreach ($queue_batch as $queue) {
// create a new scheduled task of type "sending"
@ -181,7 +181,7 @@ class Migration extends SimpleWorker {
if (!empty($task_ids)) {
foreach ($task_ids as $task_id) {
// abort if execution limit is reached
CronHelper::enforceExecutionLimit($this->timer);
$this->cron_helper->enforceExecutionLimit($this->timer);
$this->migrateTaskSubscribers($task_id);
}
@ -216,7 +216,7 @@ class Migration extends SimpleWorker {
$subscribers_to_migrate = array_slice($subscribers['to_process'], $migrated_unprocessed_count);
foreach ($subscribers_to_migrate as $sub_id) {
// abort if execution limit is reached
CronHelper::enforceExecutionLimit($this->timer);
$this->cron_helper->enforceExecutionLimit($this->timer);
ScheduledTaskSubscriber::createOrUpdate([
'task_id' => $task_id,
@ -230,7 +230,7 @@ class Migration extends SimpleWorker {
$subscribers_to_migrate = array_slice($subscribers['processed'], $migrated_processed_count);
foreach ($subscribers_to_migrate as $sub_id) {
// abort if execution limit is reached
CronHelper::enforceExecutionLimit($this->timer);
$this->cron_helper->enforceExecutionLimit($this->timer);
ScheduledTaskSubscriber::createOrUpdate([
'task_id' => $task_id,

View File

@ -45,11 +45,15 @@ class SendingQueue {
/** @var NewslettersRepository */
private $newsletters_repository;
/** @var CronHelper */
private $cron_helper;
function __construct(
SendingErrorHandler $error_handler,
StatsNotificationsScheduler $stats_notifications_scheduler,
LoggerFactory $logger_factory,
NewslettersRepository $newsletters_repository,
CronHelper $cron_helper,
$timer = false,
$mailer_task = false,
$newsletter_task = false
@ -64,6 +68,7 @@ class SendingQueue {
$this->batch_size = $wp->applyFilters('mailpoet_cron_worker_sending_queue_batch_size', self::BATCH_SIZE);
$this->logger_factory = $logger_factory;
$this->newsletters_repository = $newsletters_repository;
$this->cron_helper = $cron_helper;
}
function process() {
@ -294,7 +299,7 @@ class SendingQueue {
function enforceSendingAndExecutionLimits() {
// abort if execution limit is reached
CronHelper::enforceExecutionLimit($this->timer);
$this->cron_helper->enforceExecutionLimit($this->timer);
// abort if sending limit has been reached
MailerLog::enforceExecutionRequirements();
}