mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
QOL
This commit is contained in:
parent
c1d1f8465f
commit
7617235ec6
4
.gitignore
vendored
4
.gitignore
vendored
@ -8,4 +8,6 @@ composer.lock
|
||||
.php_cs.cache
|
||||
.env.v4
|
||||
/storage/app/indexer
|
||||
/storage/app/failovers.json
|
||||
/storage/app/failovers.json
|
||||
/storage/app/source_failover_last_downtime
|
||||
/storage/app/source_failover.lock
|
@ -15,7 +15,7 @@ use Monolog\Logger;
|
||||
class SourceHeartbeatListener
|
||||
{
|
||||
|
||||
private $logger;
|
||||
private Logger $logger;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
@ -76,6 +76,7 @@ class SourceHeartbeatListener
|
||||
{
|
||||
// create lock file
|
||||
Storage::put('source_failover.lock', '');
|
||||
Storage::put('source_failover_last_downtime', time());
|
||||
|
||||
if (env('APP_DEBUG', false)) {
|
||||
$this->logger->debug('Failover ENABLED');
|
||||
@ -91,7 +92,7 @@ class SourceHeartbeatListener
|
||||
Storage::delete('failovers.json');
|
||||
}
|
||||
|
||||
private function attemptDisableFailover()
|
||||
private function attemptDisableFailover(): bool
|
||||
{
|
||||
$score = $this->getSuccessfulRequestsScore();
|
||||
|
||||
@ -108,7 +109,7 @@ class SourceHeartbeatListener
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getLastFailoverLockTimestamp()
|
||||
private function getLastFailoverLockTimestamp(): int
|
||||
{
|
||||
try {
|
||||
return Storage::lastModified('source_failover.lock');
|
||||
|
@ -30,7 +30,7 @@ class SourceHeartbeatProvider extends ServiceProvider
|
||||
public static function getLastDowntime() : int
|
||||
{
|
||||
try {
|
||||
return Storage::lastModified('source_failover.lock');
|
||||
return Storage::lastModified('source_failover_last_downtime');
|
||||
} catch (\Exception $e) {
|
||||
return 0;
|
||||
}
|
||||
@ -67,9 +67,7 @@ class SourceHeartbeatProvider extends ServiceProvider
|
||||
}
|
||||
}
|
||||
|
||||
$scored = $score / max($totalFails, 1);
|
||||
|
||||
return $scored;
|
||||
return $score / max($totalFails, 1);
|
||||
}
|
||||
|
||||
public static function getHeartbeatStatus() : string
|
||||
|
@ -80,11 +80,9 @@ if (env('INSIGHTS', false)) {
|
||||
$app->middleware($globalMiddleware);
|
||||
|
||||
$app->routeMiddleware([
|
||||
// 'slave-auth' => App\Http\Middleware\SlaveAuthentication::class,
|
||||
// 'meta' => App\Http\Middleware\Meta::class,
|
||||
// 'cache-resolver' => App\Http\Middleware\CacheResolver::class,
|
||||
// 'throttle' => App\Http\Middleware\Throttle::class,
|
||||
// 'etag' => \App\Http\Middleware\EtagMiddleware::class,
|
||||
'microcaching' => \App\Http\Middleware\MicroCaching::class,
|
||||
'source-health-monitor' => SourceHeartbeatMonitor::class,
|
||||
]);
|
||||
@ -153,11 +151,6 @@ $app->instance('SerializerV4', SerializerFactory::createV4());
|
||||
*/
|
||||
|
||||
$commonMiddleware = [
|
||||
// 'slave-auth',
|
||||
// 'meta',
|
||||
// 'etag',
|
||||
// 'database-resolver',
|
||||
// 'cache-resolver',
|
||||
// 'throttle'
|
||||
'source-health-monitor',
|
||||
'microcaching',
|
||||
|
Loading…
x
Reference in New Issue
Block a user