Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spatie/laravel-health
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 21, 2023
2 parents 49a0e7e + 744ef62 commit 3714c9f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

All notable changes to `laravel-health` will be documented in this file.

## 1.22.3 - 2023-02-28

### What's Changed

- Update vendor name for Laravel Health Check by @rbibby in https://github.com/spatie/laravel-health/pull/161
- Fix dispatch HealthQueueJob for multiple checks by @faustoFF in https://github.com/spatie/laravel-health/pull/166

### New Contributors

- @rbibby made their first contribution in https://github.com/spatie/laravel-health/pull/161
- @faustoFF made their first contribution in https://github.com/spatie/laravel-health/pull/166

**Full Changelog**: https://github.com/spatie/laravel-health/compare/1.22.2...1.22.3

## 1.22.2 - 2023-02-15

### What's Changed
Expand Down
8 changes: 5 additions & 3 deletions src/Commands/DispatchQueueCheckJobsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ class DispatchQueueCheckJobsCommand extends Command
public function handle(): int
{
/** @var QueueCheck|null $queueCheck */
$queueCheck = Health::registeredChecks()->first(
$queueChecks = Health::registeredChecks()->filter(
fn (Check $check) => $check instanceof QueueCheck
);

foreach ($queueCheck->getQueues() as $queue) {
HealthQueueJob::dispatch($queueCheck)->onQueue($queue);
foreach ($queueChecks as $queueCheck) {
foreach ($queueCheck->getQueues() as $queue) {
HealthQueueJob::dispatch($queueCheck)->onQueue($queue);
}
}

return static::SUCCESS;
Expand Down
80 changes: 80 additions & 0 deletions tests/Commands/DispatchQueueCheckJobsCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

use Illuminate\Support\Facades\Bus;
use function Pest\Laravel\artisan;
use Spatie\Health\Checks\Checks\QueueCheck;
use Spatie\Health\Commands\DispatchQueueCheckJobsCommand;
use Spatie\Health\Facades\Health;
use Spatie\Health\Jobs\HealthQueueJob;

it('dispatch to default queue by default', function () {
Bus::fake();

Health::checks([
QueueCheck::new()->new(),
]);

artisan(DispatchQueueCheckJobsCommand::class)->assertSuccessful();

Bus::assertDispatchedTimes(HealthQueueJob::class, 1);
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'default');
});

it('dispatch to specified queue', function () {
Bus::fake();

Health::checks([
QueueCheck::new()->onQueue('queue'),
]);

artisan(DispatchQueueCheckJobsCommand::class)->assertSuccessful();

Bus::assertDispatchedTimes(HealthQueueJob::class, 1);
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue');
});

it('dispatch to multiple queues of single check', function () {
Bus::fake();

Health::checks([
QueueCheck::new()->onQueue(['queue1', 'queue2']),
]);

artisan(DispatchQueueCheckJobsCommand::class)->assertSuccessful();

Bus::assertDispatchedTimes(HealthQueueJob::class, 2);
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue1');
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue2');
});

it('dispatch multiple checks', function () {
Bus::fake();

Health::checks([
QueueCheck::new()->onQueue('queue1')->name('Queue 1'),
QueueCheck::new()->onQueue('queue2')->name('Queue 2'),
]);

artisan(DispatchQueueCheckJobsCommand::class)->assertSuccessful();

Bus::assertDispatchedTimes(HealthQueueJob::class, 2);
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue1');
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue2');
});

it('dispatch to multiple queues of multiple checks', function () {
Bus::fake();

Health::checks([
QueueCheck::new()->onQueue(['queue1', 'queue2'])->name('Queue 12'),
QueueCheck::new()->onQueue(['queue3', 'queue4'])->name('Queue 34'),
]);

artisan(DispatchQueueCheckJobsCommand::class)->assertSuccessful();

Bus::assertDispatchedTimes(HealthQueueJob::class, 4);
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue1');
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue2');
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue3');
Bus::assertDispatched(fn (HealthQueueJob $job) => $job->queue === 'queue4');
});

0 comments on commit 3714c9f

Please sign in to comment.