Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/API/V4/HealthController.php
- This file was added.
<?php | |||||
namespace App\Http\Controllers\API\V4; | |||||
use App\Http\Controllers\Controller; | |||||
class HealthController extends Controller | |||||
{ | |||||
/** | |||||
* Run a health status check | |||||
* | |||||
* @return \Illuminate\Http\JsonResponse The response | |||||
*/ | |||||
public function status() | |||||
{ | |||||
$code = \Artisan::call("status:health --check=DB --check=Redis"); | |||||
if ($code != 0) { | |||||
\Log::info("Healthcheck failed"); | |||||
$result = [ | |||||
'status' => 'error', | |||||
'output' => \Artisan::output() | |||||
]; | |||||
machniak: I would be careful here. The output may contain errors/exceptions. While services routes might… | |||||
Done Inline ActionsIt's a bit of a workaround of course to simply return the command output, but the idea is to return information to what is failing exactly, and potentially why if we can. We could decide to only return what is failing and leave the why to logging (so only ok/errpr per check), but I feel like we're making our job unnecessarily difficult if we have to go dig through logs. mollekopf: It's a bit of a workaround of course to simply return the command output, but the idea is to… | |||||
return response()->json($result, 500); | |||||
} | |||||
$result = [ | |||||
'status' => 'ok', | |||||
'output' => \Artisan::output() | |||||
]; | |||||
return response()->json($result, 200); | |||||
Not Done Inline Actions200 is the default, we're not using this argument in most of other places. machniak: 200 is the default, we're not using this argument in most of other places. | |||||
} | |||||
} |
I would be careful here. The output may contain errors/exceptions. While services routes might be secure, I think it would be nice to have some clean and structured response, i.e. JSON?