Move cron-scheduling logic from SimpleWorker to CronWorkerRunner

[MAILPOET-2539]
This commit is contained in:
Jan Jakeš
2019-11-25 13:36:12 +01:00
committed by Jack Kitterhing
parent acaaa9e2b2
commit b7294bd86c
6 changed files with 248 additions and 158 deletions

View File

@@ -7,15 +7,23 @@ use MailPoet\Cron\Workers\WorkersFactory;
class Daemon {
public $timer;
/** @var WorkersFactory */
private $workers_factory;
/** @var CronHelper */
private $cron_helper;
function __construct(WorkersFactory $workers_factory, CronHelper $cron_helper) {
/** @var CronWorkerRunner */
private $cron_worker_runner;
/** @var WorkersFactory */
private $workers_factory;
function __construct(
CronHelper $cron_helper,
CronWorkerRunner $cron_worker_runner,
WorkersFactory $workers_factory
) {
$this->timer = microtime(true);
$this->workers_factory = $workers_factory;
$this->cron_worker_runner = $cron_worker_runner;
$this->cron_helper = $cron_helper;
}
@@ -26,7 +34,11 @@ class Daemon {
$errors = [];
foreach ($this->getWorkers() as $worker) {
try {
$worker->process($this->timer);
if ($worker instanceof CronWorkerInterface) {
$this->cron_worker_runner->run($worker);
} else {
$worker->process($this->timer); // BC for workers not implementing CronWorkerInterface
}
} catch (\Exception $e) {
$worker_class_name_parts = explode('\\', get_class($worker));
$errors[] = [
@@ -46,9 +58,9 @@ class Daemon {
private function getWorkers() {
yield $this->workers_factory->createMigrationWorker();
yield $this->workers_factory->createStatsNotificationsWorker();
yield $this->workers_factory->createScheduleWorker();
yield $this->workers_factory->createQueueWorker();
yield $this->workers_factory->createStatsNotificationsWorker(); // not CronWorkerInterface compatible
yield $this->workers_factory->createScheduleWorker(); // not CronWorkerInterface compatible
yield $this->workers_factory->createQueueWorker(); // not CronWorkerInterface compatible
yield $this->workers_factory->createSendingServiceKeyCheckWorker();
yield $this->workers_factory->createPremiumKeyCheckWorker();
yield $this->workers_factory->createBounceWorker();