- prevent logging SSO errors into error.log during daily EVE server downtime +10min, closed #719

This commit is contained in:
Mark Friedrich
2018-11-29 21:21:08 +01:00
parent 07e03fce3a
commit 0e7008e72e
6 changed files with 127 additions and 9 deletions

View File

@@ -30,6 +30,7 @@ DB_UNIVERSE_PASS =
CCP_SSO_URL = https://sisilogin.testeveonline.com
CCP_SSO_CLIENT_ID =
CCP_SSO_SECRET_KEY =
CCP_SSO_DOWNTIME = 11:00
; CCP ESI API
CCP_ESI_URL = https://esi.tech.ccp.is
@@ -82,6 +83,7 @@ DB_CCP_PASS =
CCP_SSO_URL = https://login.eveonline.com
CCP_SSO_CLIENT_ID =
CCP_SSO_SECRET_KEY =
CCP_SSO_DOWNTIME = 11:00
; CCP ESI API
CCP_ESI_URL = https://esi.tech.ccp.is

View File

@@ -39,6 +39,7 @@ class Setup extends Controller {
'CCP_SSO_URL',
'CCP_SSO_CLIENT_ID',
'CCP_SSO_SECRET_KEY',
'CCP_SSO_DOWNTIME',
'CCP_ESI_URL',
'CCP_ESI_DATASOURCE',
'SMTP_HOST',

View File

@@ -0,0 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 29.11.2018
* Time: 18:12
*/
namespace Exception;
class DateException extends PathfinderException {
protected $codes = [
3000 => 500 // invalid DateRange
];
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Created by PhpStorm.
* User: Exodus 4D
* Date: 29.11.2018
* Time: 18:06
*/
namespace lib;
use Exception\DateException;
class DateRange {
/**
* from range start
* @var \DateTime
*/
protected $from;
/**
* to range end
* @var \DateTime
*/
protected $to;
/**
* DateRange constructor.
* @param \DateTime $from
* @param \DateTime $to
* @throws DateException
*/
public function __construct(\DateTime $from, \DateTime $to){
if($from == $to){
throw new DateException('A period cannot be the same time', 3000);
}else{
if($from < $to){
$this->from = $from;
$this->to = $to;
} else {
$this->from = $to;
$this->to = $from;
}
}
}
/**
* check if DateTime $dateCheck is within this range
* @param \DateTime $dateCheck
* @return bool
*/
public function inRange(\DateTime $dateCheck) : bool {
return $dateCheck >= $this->from && $dateCheck <= $this->to;
}
}

View File

@@ -373,7 +373,6 @@ class Config extends \Prefab {
){
$uri = 'tcp://' . $ip . ':' . $port;
}
return $uri;
}
@@ -391,7 +390,6 @@ class Config extends \Prefab {
}catch (Exception\ConfigException $e){
LogController::getLogger('ERROR')->write($e->getMessage());
}
return $data;
}
@@ -405,8 +403,41 @@ class Config extends \Prefab {
if(empty($status = @constant('Base::HTTP_' . $code))){
$status = @constant('self::HTTP_' . $code);
}
return $status;
}
/**
* check if a given DateTime() is within downTime range: downtime + 10m
* -> can be used for prevent logging errors during downTime
* @param \DateTime|null $dateCheck
* @return bool
* @throws Exception\DateException
* @throws \Exception
*/
static function inDownTimeRange(\DateTime $dateCheck = null) : bool {
// default daily downtime 00:00am
$downTimeParts = [0, 0];
if( !empty($downTime = (string)self::getEnvironmentData('CCP_SSO_DOWNTIME')) ){
$parts = array_map('intval', explode(':', $downTime));
if(count($parts) === 2){
// well formatted DOWNTIME found in config files
$downTimeParts = $parts;
}
}
// downTime Range is 10m
$downtimeInterval = new \DateInterval('PT10M');
$timezone = \Base::instance()->get('getTimeZone')();
// if set -> use current time
$dateCheck = is_null($dateCheck) ? new \DateTime('now', $timezone) : $dateCheck;
$dateDowntimeStart = new \DateTime('now', $timezone);
$dateDowntimeStart->setTime($downTimeParts[0],$downTimeParts[1]);
$dateDowntimeEnd = clone $dateDowntimeStart;
$dateDowntimeEnd->add($downtimeInterval);
$dateRange = new DateRange($dateDowntimeStart, $dateDowntimeEnd);
return $dateRange->inRange($dateCheck);
}
}

View File

@@ -100,8 +100,9 @@ class Web extends \Web {
* @param array $additionalOptions
* @param int $retryCount request counter for failed call
* @return array|FALSE|mixed
* @throws \Exception\DateException
*/
public function request($url,array $options = null, $additionalOptions = [], $retryCount = 0 ) {
public function request($url,array $options = null, $additionalOptions = [], $retryCount = 0){
$f3 = \Base::instance();
if( !$f3->exists( $hash = $this->getCacheKey($url, $options) ) ){
@@ -134,7 +135,11 @@ class Web extends \Web {
$url,
json_decode($result['body'])
);
LogController::getLogger('ERROR')->write($errorMsg);
// if request not within downTime time range -> log error
if( !Config::inDownTimeRange() ){
LogController::getLogger('ERROR')->write($errorMsg);
}
break;
case 500:
case 501:
@@ -150,7 +155,11 @@ class Web extends \Web {
$url,
json_decode($result['body'])
);
LogController::getLogger('ERROR')->write($errorMsg);
// if request not within downTime time range -> log error
if( !Config::inDownTimeRange() ){
LogController::getLogger('ERROR')->write($errorMsg);
}
// trigger error
if($additionalOptions['suppressHTTPErrors'] !== true){
@@ -173,8 +182,10 @@ class Web extends \Web {
json_decode($result['body'])
);
// log error
LogController::getLogger('ERROR')->write($errorMsg);
// if request not within downTime time range -> log error
if( !Config::inDownTimeRange() ){
LogController::getLogger('ERROR')->write($errorMsg);
}
if($additionalOptions['suppressHTTPErrors'] !== true){
$f3->error(504, $errorMsg);
@@ -189,7 +200,9 @@ class Web extends \Web {
$url
);
LogController::getLogger('ERROR')->write($errorMsg);
if( !Config::inDownTimeRange() ){
LogController::getLogger('ERROR')->write($errorMsg);
}
break;
}