Create worker

[MAILPOET-1859]
This commit is contained in:
Pavel Dohnal
2019-07-09 11:14:14 +02:00
committed by M. Shull
parent d79b9443b6
commit 8a86a473df
5 changed files with 48 additions and 5 deletions

View File

@ -44,6 +44,7 @@ class Daemon {
private function getWorkers() {
yield $this->workers_factory->createMigrationWorker($this->timer);
yield $this->workers_factory->createStatsNotificationsWorker($this->timer);
yield $this->workers_factory->createStatsNotificationsWorkerForAutomatedEmails($this->timer);
yield $this->workers_factory->createScheduleWorker($this->timer);
yield $this->workers_factory->createQueueWorker($this->timer);
yield $this->workers_factory->createSendingServiceKeyCheckWorker($this->timer);

View File

@ -0,0 +1,33 @@
<?php
namespace MailPoet\Cron\Workers\StatsNotifications;
use Carbon\Carbon;
use MailPoet\Cron\Workers\SimpleWorker;
use MailPoet\Models\ScheduledTask;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
if (!defined('ABSPATH')) exit;
class AutomatedEmails extends SimpleWorker {
const TASK_TYPE = 'stats_notification_automated_emails';
/** @var SettingsController */
private $settings;
function __construct(SettingsController $settings, $timer = false) {
parent::__construct($timer);
$this->settings = $settings;
}
function processTaskStrategy(ScheduledTask $task) {
// TODO
}
static function getNextRunDate() {
$wp = new WPFunctions;
$date = Carbon::createFromTimestamp($wp->currentTime('timestamp'));
return $date->next(Carbon::MONDAY)->midDay();
}
}

View File

@ -3,10 +3,11 @@
namespace MailPoet\Cron\Workers;
use MailPoet\Config\Renderer;
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationScheduler;
use MailPoet\Cron\Workers\Scheduler as SchedulerWorker;
use MailPoet\Cron\Workers\SendingQueue\SendingQueue as SendingQueueWorker;
use MailPoet\Cron\Workers\SendingQueue\Migration as MigrationWorker;
use MailPoet\Cron\Workers\StatsNotifications\AutomatedEmails as StatsNotificationsWorkerForAutomatedEmails;
use MailPoet\Cron\Workers\StatsNotifications\Scheduler as StatsNotificationScheduler;
use MailPoet\Cron\Workers\StatsNotifications\Worker as StatsNotificationsWorker;
use MailPoet\Cron\Workers\Bounce as BounceWorker;
use MailPoet\Cron\Workers\KeyCheck\PremiumKeyCheck as PremiumKeyCheckWorker;
@ -30,7 +31,7 @@ class WorkersFactory {
private $sending_error_handler;
/** @var StatsNotificationScheduler */
private $scheduler;
private $statsNotificationsScheduler;
/** @var Mailer */
private $mailer;
@ -66,7 +67,7 @@ class WorkersFactory {
public function __construct(
SendingErrorHandler $sending_error_handler,
StatsNotificationScheduler $scheduler,
StatsNotificationScheduler $statsNotificationsScheduler,
Mailer $mailer,
Renderer $renderer,
SettingsController $settings,
@ -79,7 +80,7 @@ class WorkersFactory {
SubscribersFinder $subscribers_finder
) {
$this->sending_error_handler = $sending_error_handler;
$this->scheduler = $scheduler;
$this->statsNotificationsScheduler = $statsNotificationsScheduler;
$this->mailer = $mailer;
$this->renderer = $renderer;
$this->settings = $settings;
@ -99,13 +100,19 @@ class WorkersFactory {
/** @return SendingQueueWorker */
function createQueueWorker($timer) {
return new SendingQueueWorker($this->sending_error_handler, $this->scheduler, $timer);
return new SendingQueueWorker($this->sending_error_handler, $this->statsNotificationsScheduler, $timer);
}
/** @return StatsNotificationsWorker */
function createStatsNotificationsWorker($timer) {
return new StatsNotificationsWorker($this->mailer, $this->renderer, $this->settings, $this->features_controller, $this->woocommerce_helper, $timer);
}
/** @return StatsNotificationsWorkerForAutomatedEmails */
function createStatsNotificationsWorkerForAutomatedEmails($timer) {
return new StatsNotificationsWorkerForAutomatedEmails($this->settings, $timer);
}
/** @return SendingServiceKeyCheckWorker */
function createSendingServiceKeyCheckWorker($timer) {
return new SendingServiceKeyCheckWorker($timer);

View File

@ -257,6 +257,7 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'createScheduleWorker' => $worker,
'createQueueWorker' => $worker,
'createStatsNotificationsWorker' => $worker,
'createStatsNotificationsWorkerForAutomatedEmails' => $worker,
'createSendingServiceKeyCheckWorker' => $worker,
'createPremiumKeyCheckWorker' => $worker,
'createBounceWorker' => $worker,

View File

@ -37,6 +37,7 @@ class DaemonTest extends \MailPoetTest {
'createScheduleWorker' => $this->createSimpleWorkerMock(),
'createQueueWorker' => $this->createSimpleWorkerMock(),
'createStatsNotificationsWorker' => $this->createSimpleWorkerMock(),
'createStatsNotificationsWorkerForAutomatedEmails' => $this->createSimpleWorkerMock(),
'createSendingServiceKeyCheckWorker' => $this->createSimpleWorkerMock(),
'createPremiumKeyCheckWorker' => $this->createSimpleWorkerMock(),
'createBounceWorker' => $this->createSimpleWorkerMock(),