Move plugin files to a subfolder

[MAILPOET-3988]
This commit is contained in:
Jan Jakes
2022-01-13 14:46:43 +01:00
committed by Veljko V
parent d2016701ee
commit 9f790efbf0
3200 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
namespace MailPoet\Cron\Workers\KeyCheck;
use MailPoet\Cron\CronWorkerScheduler;
use MailPoet\Cron\Workers\SimpleWorker;
use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Services\Bridge;
use MailPoet\WP\Functions as WPFunctions;
use MailPoetVendor\Carbon\Carbon;
abstract class KeyCheckWorker extends SimpleWorker {
public $bridge;
/** @var CronWorkerScheduler */
protected $cronWorkerScheduler;
public function __construct(
CronWorkerScheduler $cronWorkerScheduler,
WPFunctions $wp = null
) {
parent::__construct($wp);
$this->cronWorkerScheduler = $cronWorkerScheduler;
}
public function init() {
if (!$this->bridge) {
$this->bridge = new Bridge();
}
}
public function processTaskStrategy(ScheduledTaskEntity $task, $timer) {
try {
$result = $this->checkKey();
} catch (\Exception $e) {
$result = false;
}
if (empty($result['code']) || $result['code'] == Bridge::CHECK_ERROR_UNAVAILABLE) {
$this->cronWorkerScheduler->rescheduleProgressively($task);
return false;
}
return true;
}
public function getNextRunDate() {
$date = Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
return $date->startOfDay()
->addDay()
->addHours(rand(0, 5))
->addMinutes(rand(0, 59))
->addSeconds(rand(0, 59));
}
public abstract function checkKey();
}