forked from aaronpk/indielogin.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dc4c58
commit 2eab4dc
Showing
3 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
namespace App; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Config; | ||
use ORM; | ||
|
||
class Healthcheck { | ||
const ERROR = 'ERROR'; | ||
const OK = 'OK'; | ||
const REDIS_SUCCESSFUL_PING = 'PONG'; | ||
|
||
public function index(ServerRequestInterface $request, ResponseInterface $response) { | ||
$userlog = make_logger('healthcheck'); | ||
|
||
$services = [ | ||
'mysql' => self::ERROR, | ||
'redis' => self::ERROR, | ||
]; | ||
|
||
// Redis | ||
try { | ||
if(redis()->ping() == self::REDIS_SUCCESSFUL_PING) { | ||
$services['redis'] = self::OK; | ||
} | ||
} catch(\Predis\Connection\ConnectionException $e) { | ||
$userlog->info( | ||
'Redis connection healthcheck failure' | ||
); | ||
} | ||
|
||
// MySQL | ||
try { | ||
ORM::raw_execute('SELECT version();'); | ||
$services['mysql'] = self::OK; | ||
} catch(\Exception $e) { | ||
$userlog->info( | ||
'MySQL connection healthcheck failure' | ||
); | ||
} | ||
|
||
// Always | ||
$response->getBody()->write(json_encode($services)); | ||
return $response; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters