DI and actions
There are three equivalent entry points, and they all run the same code. Pick the one that fits the call site:
- The Health facade — the shortest, and the recommended default.
- The manager, RoundlyConsulting\Alerts\HealthManager — the facade’s root, a container singleton. Inject it through the constructor for the same API as an explicit dependency, with no static calls.
- The actions in RoundlyConsulting\Alerts\Actions — single-purpose classes with an execute() method, for composing into your own actions, jobs and commands.
Injecting the manager
use RoundlyConsulting\Alerts\HealthManager;
final class MaintenanceController
{
public function __construct(private HealthManager $health) {}
public function __invoke(Team $team): void
{
$this->health->silences()->mute('*', until: now()->addHour(), for: $team);
$this->health->for($team)->run(DiskUsageCheck::class);
}
}Health::fake() swaps the manager for the facade and for anything that injects HealthManager, so constructor-injected code is faked too.
Calling an action
use RoundlyConsulting\Alerts\Actions\MuteAlertsAction;
use RoundlyConsulting\Alerts\Actions\ScheduleHealthCheckAction;
use RoundlyConsulting\Alerts\DataTransferObjects\ScheduleHealthCheckData;
app(ScheduleHealthCheckAction::class)->execute($team, new ScheduleHealthCheckData(check: DiskUsageCheck::class));
app(MuteAlertsAction::class)->execute('disk_usage_check', until: now()->addHour());ScheduleHealthCheckAction takes the owner and a ScheduleHealthCheckData DTO (see Scheduling checks).
Facade method → action
| Facade | Action |
|---|---|
Health::for($o)->run($check) | RunHealthCheckNowAction |
Health::report() / Health::for($o)->report() | BuildHealthReportAction |
Health::for($o)->monitor(...)->save() / ->schedule($data) | ScheduleHealthCheckAction |
Health::for($o)->unmonitor($check) | UnscheduleHealthCheckAction |
Health::silences()->mute(...) | MuteAlertsAction |
Health::silences()->unmute(...) | UnmuteAlertsAction |
Health::runDue() | RunDueHealthChecksAction |
Health::prune($days) | PruneHealthCheckRunsAction |
RunHealthCheckAction is internal: it is the pipeline behind the queued HealthCheckJob and RunHealthCheckNowAction. To run a scheduled row yourself — in a custom job, for example — call Health::for($row->notifiable)->run($row).
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.