Skip to content

Commit

Permalink
Servers - Carbon::now() is better than Carbon:today() because both th…
Browse files Browse the repository at this point in the history
…e current date and time are set.
  • Loading branch information
csavelief committed May 30, 2024
1 parent 6561c65 commit ae88170
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions app/Models/YnhServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,12 @@ public function status(): ServerStatusEnum
}

// Check if status is running
$minDate = Carbon::today()->subMinutes(10);
$minDate = Carbon::now()->subMinutes(10);
$isRunning = collect(DB::select("
SELECT CASE WHEN MAX(id) IS NULL THEN 0 ELSE 1 END AS count
FROM ynh_osquery
WHERE id IN (
SELECT MAX(id) AS id
FROM ynh_osquery
WHERE ynh_server_id = {$this->id}
)
AND calendar_time >= '{$minDate->toDateTimeString()}'
SELECT COUNT(id) AS count
FROM ynh_osquery
WHERE ynh_server_id = {$this->id}
AND calendar_time >= '{$minDate->toDateTimeString()}'
"))->first();

if ($isRunning->count > 0) {
Expand All @@ -176,14 +172,10 @@ public function status(): ServerStatusEnum
// Check if status is unknown
$minDate = $minDate->subMinutes(10);
$isUnknown = collect(DB::select("
SELECT CASE WHEN MAX(id) IS NULL THEN 0 ELSE 1 END AS count
FROM ynh_osquery
WHERE id IN (
SELECT MAX(id) AS id
FROM ynh_osquery
WHERE ynh_server_id = {$this->id}
)
AND calendar_time >= '{$minDate->toDateTimeString()}'
SELECT COUNT(id) AS count
FROM ynh_osquery
WHERE ynh_server_id = {$this->id}
AND calendar_time >= '{$minDate->toDateTimeString()}'
"))->first();

if ($isUnknown->count > 0) {
Expand Down

0 comments on commit ae88170

Please sign in to comment.