summaryrefslogtreecommitdiffstats
path: root/inc/taskmanager.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 14:47:55 +0100
committerSimon Rettberg2023-11-14 14:47:55 +0100
commit06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch)
tree7e5493b102074672d8cfd8fe1a61e49f080edbe8 /inc/taskmanager.inc.php
parentUpdate phpstorm config (diff)
downloadslx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.gz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.xz
slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.zip
Add function param/return types, fix a lot more phpstorm complaints
Diffstat (limited to 'inc/taskmanager.inc.php')
-rw-r--r--inc/taskmanager.inc.php30
1 files changed, 15 insertions, 15 deletions
diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php
index 700ea4ad..6c9d63c2 100644
--- a/inc/taskmanager.inc.php
+++ b/inc/taskmanager.inc.php
@@ -19,7 +19,7 @@ class Taskmanager
*/
private static $sock = false;
- private static function init()
+ private static function init(): void
{
if (self::$sock !== false)
return;
@@ -32,7 +32,7 @@ class Taskmanager
self::send(CONFIG_TM_PASSWORD);
}
- private static function send($message)
+ private static function send(string $message): bool
{
$len = strlen($message);
$sent = socket_send(self::$sock, pack('N', $len) . $message, $len + 4, 0);
@@ -51,7 +51,7 @@ class Taskmanager
* the return value is just true (and you won't know if the task could actually be started)
* @return array{id: string, statusCode: string, data: array}|bool struct representing the task status (as a result of submit); false on communication error
*/
- public static function submit($task, $data = false, $async = false)
+ public static function submit(string $task, array $data = null, bool $async = false)
{
self::init();
$seq = (string) mt_rand();
@@ -109,7 +109,7 @@ class Taskmanager
* @param string|array $taskid a task id or a task array returned by ::status or ::submit
* @return boolean true if taskid exists in taskmanager
*/
- public static function isTask($task)
+ public static function isTask($task): bool
{
if ($task === false)
return false;
@@ -127,7 +127,7 @@ class Taskmanager
* @param int $timeout maximum time in ms to wait for completion of task
* @return array|false result/status of task, or false if it couldn't be queried
*/
- public static function waitComplete($task, $timeout = 2500)
+ public static function waitComplete($task, int $timeout = 2500)
{
if (is_array($task) && isset($task['id'])) {
if ($task['statusCode'] !== Taskmanager::TASK_PROCESSING && $task['statusCode'] !== Taskmanager::TASK_WAITING) {
@@ -140,6 +140,7 @@ class Taskmanager
return false;
$done = false;
$deadline = microtime(true) + $timeout / 1000;
+ $status = false;
while (($remaining = $deadline - microtime(true)) > 0) {
usleep((int)min(100000, $remaining * 100000));
$status = self::status($task);
@@ -163,7 +164,7 @@ class Taskmanager
* @param array|false $task struct representing task, obtained by ::status
* @return boolean true if task failed, false if finished successfully or still waiting/running
*/
- public static function isFailed($task)
+ public static function isFailed($task): bool
{
if (!is_array($task) || !isset($task['statusCode']) || !isset($task['id']))
return true;
@@ -176,10 +177,10 @@ class Taskmanager
* Check whether the given task is finished, i.e. either failed or succeeded,
* but is not running, still waiting for execution or simply unknown.
*
- * @param array $task struct representing task, obtained by ::status
+ * @param mixed $task struct representing task, obtained by ::status
* @return boolean true if task failed or finished, false if waiting for execution or currently executing, no valid task, etc.
*/
- public static function isFinished($task)
+ public static function isFinished($task): bool
{
if (!is_array($task) || !isset($task['statusCode']) || !isset($task['id']))
return false;
@@ -192,10 +193,10 @@ class Taskmanager
* Check whether the given task is running, that is either waiting for execution
* or currently executing.
*
- * @param array $task struct representing task, obtained by ::status
+ * @param mixed $task struct representing task, obtained by ::status
* @return boolean true if task is waiting or executing, false if waiting for execution or currently executing, no valid task, etc.
*/
- public static function isRunning($task)
+ public static function isRunning($task): bool
{
if (!is_array($task) || !isset($task['statusCode']) || !isset($task['id']))
return false;
@@ -204,7 +205,7 @@ class Taskmanager
return false;
}
- public static function addErrorMessage($task)
+ public static function addErrorMessage($task): void
{
static $failure = false;
if ($task === false) {
@@ -231,7 +232,7 @@ class Taskmanager
* @param string|array $task task to release. can either be its id, or a struct representing the task, as returned
* by ::submit() or ::status()
*/
- public static function release($task)
+ public static function release($task): void
{
if (is_array($task) && isset($task['id'])) {
$task = $task['id'];
@@ -247,7 +248,6 @@ class Taskmanager
/**
* Read reply from socket for given sequence number.
*
- * @param string $seq
* @return mixed the decoded json data for that message as an array, or false on error
*/
private static function readReply(string $seq)
@@ -324,7 +324,7 @@ class Taskmanager
* sending or receiving and the send or receive
* buffer might be in an undefined state.
*/
- private static function reset()
+ private static function reset(): void
{
if (self::$sock === false)
return;
@@ -335,7 +335,7 @@ class Taskmanager
/**
* @param float $deadline end time
*/
- private static function updateRecvTimeout($deadline)
+ private static function updateRecvTimeout(float $deadline): void
{
$to = $deadline - microtime(true);
if ($to <= 0) {