-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added jobs to queeue pending health checks
- Loading branch information
1 parent
791b7c6
commit 8dcd6e4
Showing
5 changed files
with
69 additions
and
2 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 |
---|---|---|
|
@@ -63,3 +63,5 @@ AWS_BUCKET= | |
AWS_USE_PATH_STYLE_ENDPOINT=false | ||
|
||
VITE_APP_NAME="${APP_NAME}" | ||
|
||
HEALTH_CHECK_INTERVAL=24 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Jobs\CheckSiteHealth; | ||
use App\Models\Site; | ||
use Carbon\Carbon; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class QueueHealthChecks extends Command | ||
{ | ||
protected int $totalPushed = 0; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:queue-health-checks'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Pushes pending health checks to queue'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$this->output->writeln('Pushing pending health checks'); | ||
|
||
Site::query() | ||
->whereDate('last_seen', '<', Carbon::now()->subHours(env('HEALTH_CHECK_INTERVAL', 24))) | ||
->chunkById( | ||
100, | ||
function (Collection $chunk) { | ||
// Show progress | ||
$this->output->write('.'); | ||
|
||
$this->totalPushed += $chunk->count(); | ||
|
||
// Push each site check to queue | ||
$chunk->each(fn($site) => CheckSiteHealth::dispatch($site)); | ||
} | ||
); | ||
|
||
// Result | ||
$this->output->writeln(""); | ||
$this->output->writeln('Pushed ' . $this->totalPushed . ' pending jobs to queue'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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