-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from kbond/refactor
[BC Break] Refactor
- Loading branch information
Showing
14 changed files
with
224 additions
and
177 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
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
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,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\History; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
abstract class Metric | ||
{ | ||
final public function failRate(): float | ||
{ | ||
try { | ||
return $this->failureCount() / $this->totalCount(); | ||
} catch (\DivisionByZeroError) { | ||
return 0; | ||
} | ||
} | ||
|
||
/** | ||
* @param positive-int $divisor Seconds | ||
*/ | ||
final public function handledPer(int $divisor): float | ||
{ | ||
$interval = $this->totalSeconds() / $divisor; | ||
|
||
return $this->totalCount() / $interval; | ||
} | ||
|
||
final public function handledPerMinute(): float | ||
{ | ||
return $this->handledPer(60); | ||
} | ||
|
||
final public function handledPerHour(): float | ||
{ | ||
return $this->handledPer(60 * 60); | ||
} | ||
|
||
final public function handledPerDay(): float | ||
{ | ||
return $this->handledPer(60 * 60 * 24); | ||
} | ||
|
||
/** | ||
* @return int milliseconds | ||
*/ | ||
final public function averageProcessingTime(): int | ||
{ | ||
return $this->averageWaitTime() + $this->averageHandlingTime(); | ||
} | ||
|
||
/** | ||
* @return int milliseconds | ||
*/ | ||
abstract public function averageWaitTime(): int; | ||
|
||
/** | ||
* @return int milliseconds | ||
*/ | ||
abstract public function averageHandlingTime(): int; | ||
|
||
abstract public function failureCount(): int; | ||
|
||
abstract public function totalCount(): int; | ||
|
||
abstract protected function totalSeconds(): int; | ||
} |
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 |
---|---|---|
|
@@ -11,62 +11,57 @@ | |
|
||
namespace Zenstruck\Messenger\Monitor\History\Model; | ||
|
||
use Zenstruck\Messenger\Monitor\History\Metric; | ||
use Zenstruck\Messenger\Monitor\Type; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class MessageTypeMetric | ||
final class MessageTypeMetric extends Metric | ||
{ | ||
public readonly Type $type; | ||
private readonly Type $type; | ||
|
||
/** | ||
* @param class-string $class | ||
* @param float $averageWaitTime In seconds | ||
* @param float $averageHandlingTime In seconds | ||
*/ | ||
public function __construct( | ||
string $class, | ||
public readonly int $totalCount, | ||
public readonly int $failureCount, | ||
public readonly float $averageWaitTime, | ||
public readonly float $averageHandlingTime, | ||
private readonly int $totalCount, | ||
private readonly int $failureCount, | ||
private readonly int $averageWaitTime, | ||
private readonly int $averageHandlingTime, | ||
private readonly int $totalSeconds, | ||
) { | ||
$this->type = new Type($class); | ||
} | ||
|
||
public function failRate(): float | ||
public function type(): Type | ||
{ | ||
try { | ||
return $this->failureCount / $this->totalCount; | ||
} catch (\DivisionByZeroError) { | ||
return 0; | ||
} | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @param positive-int $divisor Seconds | ||
*/ | ||
public function handledPer(int $divisor): float | ||
public function averageWaitTime(): int | ||
{ | ||
$interval = $this->totalSeconds / $divisor; | ||
return $this->averageWaitTime; | ||
} | ||
|
||
return $this->totalCount / $interval; | ||
public function averageHandlingTime(): int | ||
{ | ||
return $this->averageHandlingTime; | ||
} | ||
|
||
public function handledPerMinute(): float | ||
public function failureCount(): int | ||
{ | ||
return $this->handledPer(60); | ||
return $this->failureCount; | ||
} | ||
|
||
public function handledPerHour(): float | ||
public function totalCount(): int | ||
{ | ||
return $this->handledPer(60 * 60); | ||
return $this->totalCount; | ||
} | ||
|
||
public function handledPerDay(): float | ||
protected function totalSeconds(): int | ||
{ | ||
return $this->handledPer(60 * 60 * 24); | ||
return $this->totalSeconds; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -20,12 +20,12 @@ | |
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class Snapshot | ||
final class Snapshot extends Metric | ||
{ | ||
private int $successCount; | ||
private int $failureCount; | ||
private float $averageWaitTime; | ||
private float $averageHandlingTime; | ||
private int $averageWaitTime; | ||
private int $averageHandlingTime; | ||
private int $totalSeconds; | ||
|
||
public function __construct(private Storage $storage, private Specification $specification) | ||
|
@@ -68,62 +68,14 @@ public function failureCount(): int | |
return $this->failureCount ??= $this->storage->count($this->specification->failures()); | ||
} | ||
|
||
public function failRate(): float | ||
public function averageWaitTime(): int | ||
{ | ||
try { | ||
return $this->failureCount() / $this->totalCount(); | ||
} catch (\DivisionByZeroError) { | ||
return 0; | ||
} | ||
} | ||
|
||
/** | ||
* @return float In seconds | ||
*/ | ||
public function averageWaitTime(): float | ||
{ | ||
return $this->averageWaitTime ??= $this->storage->averageWaitTime($this->specification) ?? 0.0; | ||
} | ||
|
||
/** | ||
* @return float In seconds | ||
*/ | ||
public function averageHandlingTime(): float | ||
{ | ||
return $this->averageHandlingTime ??= $this->storage->averageHandlingTime($this->specification) ?? 0.0; | ||
} | ||
|
||
/** | ||
* @return float In seconds | ||
*/ | ||
public function averageProcessingTime(): float | ||
{ | ||
return $this->averageWaitTime() + $this->averageHandlingTime(); | ||
} | ||
|
||
/** | ||
* @param positive-int $divisor Seconds | ||
*/ | ||
public function handledPer(int $divisor): float | ||
{ | ||
$interval = $this->totalSeconds() / $divisor; | ||
|
||
return $this->totalCount() / $interval; | ||
} | ||
|
||
public function handledPerMinute(): float | ||
{ | ||
return $this->handledPer(60); | ||
} | ||
|
||
public function handledPerHour(): float | ||
{ | ||
return $this->handledPer(60 * 60); | ||
return $this->averageWaitTime ??= $this->storage->averageWaitTime($this->specification) ?? 0; | ||
} | ||
|
||
public function handledPerDay(): float | ||
public function averageHandlingTime(): int | ||
{ | ||
return $this->handledPer(60 * 60 * 24); | ||
return $this->averageHandlingTime ??= $this->storage->averageHandlingTime($this->specification) ?? 0; | ||
} | ||
|
||
public function totalSeconds(): int | ||
|
Oops, something went wrong.