From d5d515d63b146b06f9105bc6d7e30d6cb9d472e1 Mon Sep 17 00:00:00 2001 From: Netkas Date: Thu, 9 Feb 2023 13:25:32 -0500 Subject: [PATCH] Added method \TamerLib\Classes > Functions > calculatePriority() --- src/TamerLib/Classes/Functions.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/TamerLib/Classes/Functions.php b/src/TamerLib/Classes/Functions.php index d31d8a6..34e7e58 100644 --- a/src/TamerLib/Classes/Functions.php +++ b/src/TamerLib/Classes/Functions.php @@ -7,9 +7,9 @@ use OptsLib\Parse; use Symfony\Component\Process\PhpExecutableFinder; use TamerLib\Abstracts\ProtocolType; + use TamerLib\Abstracts\TaskPriority; use TamerLib\Interfaces\ClientProtocolInterface; use TamerLib\Interfaces\WorkerProtocolInterface; - class Functions { /** @@ -127,4 +127,21 @@ self::$php_bin = $php_bin; return $php_bin; } + + /** + * Calculates the priority for a task based on the priority level + * + * @param int $priority + * @return int + */ + public static function calculatePriority(int $priority): int + { + if($priority < TaskPriority::Low) + return 0; + + if($priority > TaskPriority::High) + return 255; + + return (int) round(($priority / TaskPriority::High) * 255); + } } \ No newline at end of file