Added Logging calls to \ncc\Managers > ExecutionPointerManager
This commit is contained in:
parent
c2b7b31802
commit
e878ce4ff9
1 changed files with 40 additions and 2 deletions
|
@ -84,10 +84,13 @@
|
||||||
if(count($this->TemporaryUnits) == 0)
|
if(count($this->TemporaryUnits) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Console::outVerbose('Cleaning temporary units...');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach($this->TemporaryUnits as $datum)
|
foreach($this->TemporaryUnits as $datum)
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('deleting unit %s=%s.%s', $datum['package'], $datum['version'], $datum['name']));
|
||||||
$this->removeUnit($datum['package'], $datum['version'], $datum['name']);
|
$this->removeUnit($datum['package'], $datum['version'], $datum['name']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,16 +125,23 @@
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws UnsupportedRunnerException
|
* @throws UnsupportedRunnerException
|
||||||
* @noinspection PhpUnused
|
* @noinspection PhpUnused
|
||||||
|
* @noinspection DuplicatedCode
|
||||||
*/
|
*/
|
||||||
public function addUnit(string $package, string $version, ExecutionUnit $unit, bool $temporary=false): void
|
public function addUnit(string $package, string $version, ExecutionUnit $unit, bool $temporary=false): void
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::System)
|
if(Resolver::resolveScope() !== Scopes::System)
|
||||||
throw new AccessDeniedException('Cannot add new ExecutionUnit \'' . $unit->ExecutionPolicy->Name .'\' for ' . $package . ', insufficient permissions');
|
throw new AccessDeniedException('Cannot add new ExecutionUnit \'' . $unit->ExecutionPolicy->Name .'\' for ' . $package . ', insufficient permissions');
|
||||||
|
|
||||||
|
Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->ExecutionPolicy->Name, $package));
|
||||||
|
|
||||||
$package_id = $this->getPackageId($package, $version);
|
$package_id = $this->getPackageId($package, $version);
|
||||||
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
||||||
$package_bin_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id;
|
$package_bin_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id;
|
||||||
|
|
||||||
|
Console::outDebug(sprintf('package_id=%s', $package_id));
|
||||||
|
Console::outDebug(sprintf('package_config_path=%s', $package_config_path));
|
||||||
|
Console::outDebug(sprintf('package_bin_path=%s', $package_bin_path));
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
|
|
||||||
// Either load or create the pointers file
|
// Either load or create the pointers file
|
||||||
|
@ -156,6 +166,8 @@
|
||||||
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Console::outDebug(sprintf('bin_file=%s', $bin_file));
|
||||||
|
|
||||||
if($filesystem->exists($bin_file) && $temporary)
|
if($filesystem->exists($bin_file) && $temporary)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -189,16 +201,23 @@
|
||||||
* @throws AccessDeniedException
|
* @throws AccessDeniedException
|
||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
|
* @noinspection DuplicatedCode
|
||||||
*/
|
*/
|
||||||
public function removeUnit(string $package, string $version, string $name): bool
|
public function removeUnit(string $package, string $version, string $name): bool
|
||||||
{
|
{
|
||||||
if(Resolver::resolveScope() !== Scopes::System)
|
if(Resolver::resolveScope() !== Scopes::System)
|
||||||
throw new AccessDeniedException('Cannot remove ExecutionUnit \'' . $name .'\' for ' . $package . ', insufficient permissions');
|
throw new AccessDeniedException('Cannot remove ExecutionUnit \'' . $name .'\' for ' . $package . ', insufficient permissions');
|
||||||
|
|
||||||
|
Console::outVerbose(sprintf('Removing ExecutionUnit \'%s\' for %s', $name, $package));
|
||||||
|
|
||||||
$package_id = $this->getPackageId($package, $version);
|
$package_id = $this->getPackageId($package, $version);
|
||||||
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
||||||
$package_bin_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id;
|
$package_bin_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id;
|
||||||
|
|
||||||
|
Console::outDebug(sprintf('package_id=%s', $package_id));
|
||||||
|
Console::outDebug(sprintf('package_config_path=%s', $package_config_path));
|
||||||
|
Console::outDebug(sprintf('package_bin_path=%s', $package_bin_path));
|
||||||
|
|
||||||
$filesystem = new Filesystem();
|
$filesystem = new Filesystem();
|
||||||
if(!$filesystem->exists($package_config_path))
|
if(!$filesystem->exists($package_config_path))
|
||||||
return false;
|
return false;
|
||||||
|
@ -237,6 +256,8 @@
|
||||||
*/
|
*/
|
||||||
public function getUnits(string $package, string $version): array
|
public function getUnits(string $package, string $version): array
|
||||||
{
|
{
|
||||||
|
Console::outVerbose(sprintf('getting execution units for %s', $package));
|
||||||
|
|
||||||
$package_id = $this->getPackageId($package, $version);
|
$package_id = $this->getPackageId($package, $version);
|
||||||
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
||||||
|
|
||||||
|
@ -247,6 +268,7 @@
|
||||||
$results = [];
|
$results = [];
|
||||||
foreach($execution_pointers->getPointers() as $pointer)
|
foreach($execution_pointers->getPointers() as $pointer)
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('unit %s', $pointer->ExecutionPolicy->Name));
|
||||||
$results[] = $pointer->ExecutionPolicy->Name;
|
$results[] = $pointer->ExecutionPolicy->Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +292,8 @@
|
||||||
*/
|
*/
|
||||||
public function executeUnit(string $package, string $version, string $name): void
|
public function executeUnit(string $package, string $version, string $name): void
|
||||||
{
|
{
|
||||||
|
Console::outVerbose(sprintf('executing unit %s for %s', $name, $package));
|
||||||
|
|
||||||
$package_id = $this->getPackageId($package, $version);
|
$package_id = $this->getPackageId($package, $version);
|
||||||
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
$package_config_path = $this->RunnerPath . DIRECTORY_SEPARATOR . $package_id . '.inx';
|
||||||
|
|
||||||
|
@ -282,6 +306,10 @@
|
||||||
if($unit == null)
|
if($unit == null)
|
||||||
throw new ExecutionUnitNotFoundException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\'');
|
throw new ExecutionUnitNotFoundException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\'');
|
||||||
|
|
||||||
|
Console::outDebug(sprintf('unit=%s', $unit->ExecutionPolicy->Name));
|
||||||
|
Console::outDebug(sprintf('runner=%s', $unit->ExecutionPolicy->Runner));
|
||||||
|
Console::outDebug(sprintf('file=%s', $unit->FilePointer));
|
||||||
|
|
||||||
$process = match (strtolower($unit->ExecutionPolicy->Runner))
|
$process = match (strtolower($unit->ExecutionPolicy->Runner))
|
||||||
{
|
{
|
||||||
Runners::bash => BashRunner::prepareProcess($unit),
|
Runners::bash => BashRunner::prepareProcess($unit),
|
||||||
|
@ -289,7 +317,7 @@
|
||||||
Runners::perl => PerlRunner::prepareProcess($unit),
|
Runners::perl => PerlRunner::prepareProcess($unit),
|
||||||
Runners::python => PythonRunner::prepareProcess($unit),
|
Runners::python => PythonRunner::prepareProcess($unit),
|
||||||
Runners::python2 => Python2Runner::prepareProcess($unit),
|
Runners::python2 => Python2Runner::prepareProcess($unit),
|
||||||
Runners::python3 => Python3Runner::prepareProcess($unt),
|
Runners::python3 => Python3Runner::prepareProcess($unit),
|
||||||
Runners::lua => LuaRunner::prepareProcess($unit),
|
Runners::lua => LuaRunner::prepareProcess($unit),
|
||||||
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
default => throw new UnsupportedRunnerException('The runner \'' . $unit->ExecutionPolicy->Runner . '\' is not supported'),
|
||||||
};
|
};
|
||||||
|
@ -314,12 +342,18 @@
|
||||||
$process->enableOutput();
|
$process->enableOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory()));
|
||||||
|
Console::outDebug(sprintf('timeout=%s', ($process->getTimeout() ?? 0)));
|
||||||
|
Console::outDebug(sprintf('silent=%s', ($unit->ExecutionPolicy->Execute->Silent ? 'true' : 'false')));
|
||||||
|
Console::outDebug(sprintf('tty=%s', ($unit->ExecutionPolicy->Execute->Tty ? 'true' : 'false')));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if($unit->ExecutionPolicy->Message !== null)
|
if($unit->ExecutionPolicy->Message !== null)
|
||||||
Console::out($unit->ExecutionPolicy->Message);
|
Console::out($unit->ExecutionPolicy->Message);
|
||||||
|
|
||||||
$process->run(function ($type, $buffer) {
|
$process->run(function ($type, $buffer)
|
||||||
|
{
|
||||||
Console::out($buffer);
|
Console::out($buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -331,6 +365,8 @@
|
||||||
$this->handleExit($package, $version, $unit->ExecutionPolicy->ExitHandlers->Error);
|
$this->handleExit($package, $version, $unit->ExecutionPolicy->ExitHandlers->Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console::outDebug(sprintf('exit_code=%s', $process->getExitCode()));
|
||||||
|
|
||||||
if($unit->ExecutionPolicy->ExitHandlers !== null)
|
if($unit->ExecutionPolicy->ExitHandlers !== null)
|
||||||
{
|
{
|
||||||
if($process->isSuccessful() && $unit->ExecutionPolicy->ExitHandlers->Success !== null)
|
if($process->isSuccessful() && $unit->ExecutionPolicy->ExitHandlers->Success !== null)
|
||||||
|
@ -428,11 +464,13 @@
|
||||||
}
|
}
|
||||||
elseif($exitHandle->EndProcess)
|
elseif($exitHandle->EndProcess)
|
||||||
{
|
{
|
||||||
|
Console::outDebug(sprintf('exit_code=%s', $process->getExitCode()));
|
||||||
exit($exitHandle->ExitCode);
|
exit($exitHandle->ExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($exitHandle->Run !== null)
|
if($exitHandle->Run !== null)
|
||||||
{
|
{
|
||||||
|
Console::outVerbose('Running unit \'' . $exitHandle->Run . '\'');
|
||||||
$this->executeUnit($package, $version, $exitHandle->Run);
|
$this->executeUnit($package, $version, $exitHandle->Run);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue