Extract simple workers common code into a base class [PREMIUM-4]

This commit is contained in:
Alexey Stoletniy
2017-05-08 07:38:56 +03:00
parent 4b1f216cd3
commit 3f151fd235
18 changed files with 416 additions and 649 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace MailPoet\Cron\Workers\KeyCheck;
use MailPoet\Cron\CronHelper;
use MailPoet\Cron\Workers\SimpleWorker;
use MailPoet\Models\SendingQueue;
use MailPoet\Services\Bridge;
if(!defined('ABSPATH')) exit;
abstract class KeyCheckWorker extends SimpleWorker {
const UNAVAILABLE_SERVICE_RESCHEDULE_TIMEOUT = 60;
public $bridge;
function initApi() {
if(!$this->bridge) {
$this->bridge = new Bridge();
}
}
function processQueueLogic(SendingQueue $queue) {
try {
$result = $this->checkKey();
} catch (\Exception $e) {
$result = false;
}
if(empty($result['code']) || $result['code'] == Bridge::CHECK_ERROR_UNAVAILABLE) {
$this->reschedule($queue, self::UNAVAILABLE_SERVICE_RESCHEDULE_TIMEOUT);
return false;
}
return true;
}
abstract function checkKey();
}