-
-
Notifications
You must be signed in to change notification settings - Fork 17
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 <kevinbond@gmail.com> | ||
* | ||
* 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 <kevinbond@gmail.com> | ||
*/ | ||
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
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
Oops, something went wrong.