Tweak Sending Service key validation after a code review [MAILPOET-743]

* Abstract key state to unbound it from the API response codes
* Rename SendingServiceKeyCheck task for clarity
* Add a setter for the API key in the Bridge API class
* Make some smaller fixes
This commit is contained in:
Alexey Stoletniy
2017-01-23 23:40:20 +03:00
parent 425d45a862
commit 98d6f55a6e
13 changed files with 123 additions and 83 deletions

View File

@@ -10,7 +10,7 @@ use MailPoet\Services\Bridge;
if(!defined('ABSPATH')) exit;
class SendingServiceKeyCheck {
const TASK_TYPE = 'sskeycheck';
const TASK_TYPE = 'sending_service_key_check';
const UNAVAILABLE_SERVICE_RESCHEDULE_TIMEOUT = 60;
public $timer;
@@ -89,10 +89,10 @@ class SendingServiceKeyCheck {
$mailer_config = Mailer::getMailerConfig();
$result = $this->bridge->checkKey($mailer_config['mailpoet_api_key']);
} catch (\Exception $e) {
$result = array('code' => 503);
$result = false;
}
if(empty($result['code']) || $result['code'] == 503) {
if(empty($result['code']) || $result['code'] == Bridge::CHECK_ERROR_UNAVAILABLE) {
// reschedule the check
$scheduled_at = Carbon::createFromTimestamp(current_time('timestamp'));
$queue->scheduled_at = $scheduled_at->addMinutes(