You are viewing documentation for an outdated version. It is no longer supported!

Events

The following are the events that the circuit breaker dispatches. These can, for instance, be used to create "service monitoring" logic.

Each of these events offer the following methods:

  • state(): Returns the circuit breaker's current State.
  • lastFailure(): Returns the last reported Failure or null, if none available.

Both State and Failure are immutable objects. Please review Aedart\Contracts\Circuits\State and Aedart\Contracts\Circuits\Failure for additional information.

Has Closed

Aedart\Contracts\Circuits\Events\HasClosed is dispatched when state, is changed to Closed state (initial / success state).

Has Open

Aedart\Contracts\Circuits\Events\HasOpened is dispatched when state, is changed to Open state (circuit has tripped / failure state).

Has Half-Open

Aedart\Contracts\Circuits\Events\HasHalfOpened is dispatched when state, is changed to Half-Open state (intermediate state / recovery attempt state).

Failure Reported

Whenever a failure has been reported, Aedart\Contracts\Circuits\Events\FailureReported is dispatched. This event offers a failure() method. It guarantees to return a Failure object, that contains information about the reported failure.

use Aedart\Contracts\Circuits\Events\FailureReported;

class NotifyOnWhetherServiceFailure
{
    public function handle(FailureReported $event)
    {
        $failure = $event->failure();

        $reason = $failure->reason();
        $failureTime = $failure->reportedAt();
        $totalReportedFailures = $failure->totalFailures();

        // Send notification about failure ... not shown here...
    }
}