Share the $wp property between workers

[MAILPOET-2396]
This commit is contained in:
Amine Ben hammou
2019-12-11 13:30:52 +01:00
committed by Jack Kitterhing
parent 2a70a4813c
commit 20eccaad67
5 changed files with 11 additions and 15 deletions

View File

@@ -18,21 +18,22 @@ abstract class SimpleWorker implements CronWorkerInterface {
public $timer;
/** @var WPFunctions */
private $wp;
/** @var CronHelper */
protected $cron_helper;
/** @var CronWorkerScheduler */
protected $cron_worker_scheduler;
public function __construct() {
/** @var WPFunctions */
protected $wp;
public function __construct(WPFunctions $wp = null) {
if (static::TASK_TYPE === null) {
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_worker_scheduler = ContainerWrapper::getInstance()->get(CronWorkerScheduler::class);
}