Added method \TamerLib\Classes > Functions > calculatePriority()
This commit is contained in:
parent
4e474b3449
commit
d5d515d63b
1 changed files with 18 additions and 1 deletions
|
@ -7,9 +7,9 @@
|
||||||
use OptsLib\Parse;
|
use OptsLib\Parse;
|
||||||
use Symfony\Component\Process\PhpExecutableFinder;
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
use TamerLib\Abstracts\ProtocolType;
|
use TamerLib\Abstracts\ProtocolType;
|
||||||
|
use TamerLib\Abstracts\TaskPriority;
|
||||||
use TamerLib\Interfaces\ClientProtocolInterface;
|
use TamerLib\Interfaces\ClientProtocolInterface;
|
||||||
use TamerLib\Interfaces\WorkerProtocolInterface;
|
use TamerLib\Interfaces\WorkerProtocolInterface;
|
||||||
|
|
||||||
class Functions
|
class Functions
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -127,4 +127,21 @@
|
||||||
self::$php_bin = $php_bin;
|
self::$php_bin = $php_bin;
|
||||||
return $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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue