Share the $wp property between workers
[MAILPOET-2396]
This commit is contained in:
committed by
Jack Kitterhing
parent
2a70a4813c
commit
20eccaad67
@ -15,13 +15,9 @@ class Beamer extends SimpleWorker {
|
|||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
private $settings;
|
private $settings;
|
||||||
|
|
||||||
/** @var WPFunctions */
|
|
||||||
private $wp;
|
|
||||||
|
|
||||||
public function __construct(SettingsController $settings, WPFunctions $wp) {
|
public function __construct(SettingsController $settings, WPFunctions $wp) {
|
||||||
parent::__construct();
|
parent::__construct($wp);
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
$this->wp = $wp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processTaskStrategy(ScheduledTask $task, $timer) {
|
public function processTaskStrategy(ScheduledTask $task, $timer) {
|
||||||
@ -43,8 +39,7 @@ class Beamer extends SimpleWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getNextRunDate() {
|
public function getNextRunDate() {
|
||||||
$wp = new WPFunctions;
|
$date = Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
|
||||||
$date = Carbon::createFromTimestamp($wp->currentTime('timestamp'));
|
|
||||||
return $date->hour(11)->minute(00)->second(00)->addDay();
|
return $date->hour(11)->minute(00)->second(00)->addDay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Cron\Workers\KeyCheck;
|
namespace MailPoet\Cron\Workers\KeyCheck;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use MailPoet\Cron\Workers\SimpleWorker;
|
use MailPoet\Cron\Workers\SimpleWorker;
|
||||||
use MailPoet\Models\ScheduledTask;
|
use MailPoet\Models\ScheduledTask;
|
||||||
use MailPoet\Services\Bridge;
|
use MailPoet\Services\Bridge;
|
||||||
|
@ -18,21 +18,22 @@ abstract class SimpleWorker implements CronWorkerInterface {
|
|||||||
|
|
||||||
public $timer;
|
public $timer;
|
||||||
|
|
||||||
/** @var WPFunctions */
|
|
||||||
private $wp;
|
|
||||||
|
|
||||||
/** @var CronHelper */
|
/** @var CronHelper */
|
||||||
protected $cron_helper;
|
protected $cron_helper;
|
||||||
|
|
||||||
/** @var CronWorkerScheduler */
|
/** @var CronWorkerScheduler */
|
||||||
protected $cron_worker_scheduler;
|
protected $cron_worker_scheduler;
|
||||||
|
|
||||||
public function __construct() {
|
/** @var WPFunctions */
|
||||||
|
protected $wp;
|
||||||
|
|
||||||
|
public function __construct(WPFunctions $wp = null) {
|
||||||
if (static::TASK_TYPE === null) {
|
if (static::TASK_TYPE === null) {
|
||||||
throw new \Exception('Constant TASK_TYPE is not defined on subclass ' . get_class($this));
|
throw new \Exception('Constant TASK_TYPE is not defined on subclass ' . get_class($this));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wp = new WPFunctions();
|
if ($wp === null) $wp = ContainerWrapper::getInstance()->get(WPFunctions::class);
|
||||||
|
$this->wp = $wp;
|
||||||
$this->cron_helper = ContainerWrapper::getInstance()->get(CronHelper::class);
|
$this->cron_helper = ContainerWrapper::getInstance()->get(CronHelper::class);
|
||||||
$this->cron_worker_scheduler = ContainerWrapper::getInstance()->get(CronWorkerScheduler::class);
|
$this->cron_worker_scheduler = ContainerWrapper::getInstance()->get(CronWorkerScheduler::class);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ class UnsubscribeTokens extends SimpleWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getNextRunDate() {
|
public function getNextRunDate() {
|
||||||
$wp = new WPFunctions;
|
return Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
|
||||||
return Carbon::createFromTimestamp($wp->currentTime('timestamp'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,6 @@ class WooCommercePastOrders extends SimpleWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getNextRunDate() {
|
public function getNextRunDate() {
|
||||||
return Carbon::createFromTimestamp(WPFunctions::get()->currentTime('timestamp')); // schedule immediately
|
return Carbon::createFromTimestamp($this->wp->currentTime('timestamp')); // schedule immediately
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user