diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/event.inc.php | 4 | ||||
-rw-r--r-- | inc/module.inc.php | 7 | ||||
-rw-r--r-- | inc/taskmanager.inc.php | 6 | ||||
-rw-r--r-- | inc/trigger.inc.php | 10 |
4 files changed, 19 insertions, 8 deletions
diff --git a/inc/event.inc.php b/inc/event.inc.php index e5ade41b..2d916b48 100644 --- a/inc/event.inc.php +++ b/inc/event.inc.php @@ -64,7 +64,7 @@ class Event } else { $res = Taskmanager::waitComplete($ipxeId, 5000); if (Taskmanager::isFailed($res)) { - EventLog::failure('Update PXE Menu failed', $res['data']['error']); + EventLog::failure('Update PXE Menu failed', $res['data']['error'] ?? $res['data']['error'] ?? ''); $everythingFine = false; } } @@ -79,7 +79,7 @@ class Event $mountStatus = Taskmanager::waitComplete($mountId, 10000); } if ($mountId !== false && Taskmanager::isFailed($mountStatus)) { - EventLog::failure('Mounting VM store failed', $mountStatus['data']['messages']); + EventLog::failure('Mounting VM store failed', $mountStatus['data']['messages'] ?? ''); $everythingFine = false; } elseif ($mountId !== false && !Taskmanager::isFinished($mountStatus)) { // TODO: Still running - create callback diff --git a/inc/module.inc.php b/inc/module.inc.php index 5525c0a4..55713cd0 100644 --- a/inc/module.inc.php +++ b/inc/module.inc.php @@ -10,7 +10,12 @@ class Module * @var \Module[] */ private static $modules = false; - + + /** + * @param string $name ID/Internal name of module + * @param false $ignoreDepFail whether to return the module even if some of its dependencies failed + * @return false|Module + */ public static function get($name, $ignoreDepFail = false) { if (!isset(self::$modules[$name])) diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php index 85d5ee39..f7c72e04 100644 --- a/inc/taskmanager.inc.php +++ b/inc/taskmanager.inc.php @@ -140,7 +140,8 @@ class Taskmanager return false; $done = false; $deadline = microtime(true) + $timeout / 1000; - do { + while (($remaining = $deadline - microtime(true)) > 0) { + usleep(min(100000, $remaining * 100000)); $status = self::status($task); if (!isset($status['statusCode'])) break; @@ -148,8 +149,7 @@ class Taskmanager $done = true; break; } - usleep(100000); - } while (microtime(true) < $deadline); + } if ($done) { // For now we do this unconditionally, but maybe we want to keep them longer some time? self::release($task); } diff --git a/inc/trigger.inc.php b/inc/trigger.inc.php index 134bab53..5024b907 100644 --- a/inc/trigger.inc.php +++ b/inc/trigger.inc.php @@ -98,7 +98,7 @@ class Trigger * * @param array $vmstore VM Store configuration to use. If false, read from properties * @param bool $ifLocalOnly Only execute task if the storage type is local (used for DNBD3) - * @return array|false task status of mount procedure, or false on error + * @return string|false task id of mount procedure, or false on error */ public static function mount($vmstore = false, $ifLocalOnly = false) { @@ -130,7 +130,7 @@ class Trigger }else { $opts = null; } - return Taskmanager::submit('MountVmStore', array( + $status = Taskmanager::submit('MountVmStore', array( 'address' => $addr, 'type' => 'images', 'opts' => $opts, @@ -138,6 +138,12 @@ class Trigger 'username' => $vmstore['cifsuser'], 'password' => $vmstore['cifspasswd'] )); + if (!Taskmanager::isFailed($status)) { + // In case we have a concurrent active task, this should be enough + // for the taskmanager to give us the existing id + $status = Taskmanager::waitComplete($status, 100); + } + return $status['data']['existingTask'] ?? $status['id'] ?? false; } /** |