mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-22 00:32:16 +02:00
N°9165 - Moved ExecutionLimits
This commit is contained in:
@@ -3216,30 +3216,4 @@ TXT
|
|||||||
return (int)$sLimit;
|
return (int)$sLimit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if execution should stop due to time limit or memory limit
|
|
||||||
*
|
|
||||||
* @param int $iMaxTime Absolute max time in seconds since epoch
|
|
||||||
* @param int $iMaxMemoryPercent Percent of memory usage allowed (0-100)
|
|
||||||
*
|
|
||||||
* @return bool true if execution should stop
|
|
||||||
*/
|
|
||||||
public static function ShouldStopExecution(int $iMaxTime = 0, int $iMaxMemoryPercent = 100): bool
|
|
||||||
{
|
|
||||||
if (($iMaxTime != 0) && (time() > $iMaxTime)) {
|
|
||||||
\IssueLog::Debug(__METHOD__.' timeout '.time()." (current) > $iMaxTime (max)");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$iMaxMemoryPercent = (int)min(max($iMaxMemoryPercent, 0), 100);
|
|
||||||
$iMemory = memory_get_usage(true);
|
|
||||||
$iMaxMemory = self::GetMemoryLimit() * $iMaxMemoryPercent / 100;
|
|
||||||
if ($iMemory > $iMaxMemory) {
|
|
||||||
\IssueLog::Debug(__METHOD__." Memory limit $iMemory (current) > $iMaxMemory (max)");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @copyright Copyright (C) 2010-2026 Combodo SAS
|
|
||||||
* @license http://opensource.org/licenses/AGPL-3.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Combodo\iTop\DataFeatureRemoval\Helper;
|
|
||||||
|
|
||||||
use utils;
|
|
||||||
|
|
||||||
class ExecutionLimits
|
|
||||||
{
|
|
||||||
private int $iMaxTime;
|
|
||||||
private int $iMaxMemoryPercent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $iMaxTime
|
|
||||||
* @param int $iMaxMemoryPercent
|
|
||||||
*/
|
|
||||||
public function __construct(int $iMaxTime = 0, int $iMaxMemoryPercent = 100)
|
|
||||||
{
|
|
||||||
$this->iMaxTime = $iMaxTime;
|
|
||||||
$this->iMaxMemoryPercent = $iMaxMemoryPercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ShouldStopExecution(): bool
|
|
||||||
{
|
|
||||||
return utils::ShouldStopExecution($this->iMaxTime, $this->iMaxMemoryPercent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,12 +3,10 @@
|
|||||||
namespace Combodo\iTop\DataFeatureRemoval\Service;
|
namespace Combodo\iTop\DataFeatureRemoval\Service;
|
||||||
|
|
||||||
use CMDBObjectSet;
|
use CMDBObjectSet;
|
||||||
use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalException;
|
|
||||||
use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalLog;
|
use Combodo\iTop\DataFeatureRemoval\Helper\DataFeatureRemovalLog;
|
||||||
use Combodo\iTop\DataFeatureRemoval\Helper\ExecutionLimits;
|
use Combodo\iTop\Service\Limits\ExecutionLimits;
|
||||||
use DBObject;
|
use DBObject;
|
||||||
use DBObjectSearch;
|
use DBObjectSearch;
|
||||||
use Dict;
|
|
||||||
use MetaModel;
|
use MetaModel;
|
||||||
|
|
||||||
class DataCleanupService
|
class DataCleanupService
|
||||||
@@ -20,8 +18,7 @@ class DataCleanupService
|
|||||||
public function __construct(int $iMaxExecutionTime = 30, int $iMaxMemoryPercent = 80)
|
public function __construct(int $iMaxExecutionTime = 30, int $iMaxMemoryPercent = 80)
|
||||||
{
|
{
|
||||||
DataFeatureRemovalLog::Enable();
|
DataFeatureRemovalLog::Enable();
|
||||||
$iMaxTime = time() + $iMaxExecutionTime;
|
$this->oExecutionLimits = new ExecutionLimits($iMaxExecutionTime, $iMaxMemoryPercent);
|
||||||
$this->oExecutionLimits = new ExecutionLimits($iMaxTime, $iMaxMemoryPercent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ return array(
|
|||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalException' => $baseDir . '/src/Helper/DataFeatureRemovalException.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalException' => $baseDir . '/src/Helper/DataFeatureRemovalException.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalHelper' => $baseDir . '/src/Helper/DataFeatureRemovalHelper.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalHelper' => $baseDir . '/src/Helper/DataFeatureRemovalHelper.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalLog' => $baseDir . '/src/Helper/DataFeatureRemovalLog.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalLog' => $baseDir . '/src/Helper/DataFeatureRemovalLog.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\ExecutionLimits' => $baseDir . '/src/Helper/ExecutionLimits.php',
|
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataCleanupService' => $baseDir . '/src/Service/DataCleanupService.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataCleanupService' => $baseDir . '/src/Service/DataCleanupService.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataFeatureRemoverExtensionService' => $baseDir . '/src/Service/DataFeatureRemoverExtensionService.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataFeatureRemoverExtensionService' => $baseDir . '/src/Service/DataFeatureRemoverExtensionService.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\ObjectService' => $baseDir . '/src/Service/ObjectService.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Service\\ObjectService' => $baseDir . '/src/Service/ObjectService.php',
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ class ComposerStaticInit4f96a7199e2c0d90e547333758b26464
|
|||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalException' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalException.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalException' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalException.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalHelper' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalHelper.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalHelper' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalHelper.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalLog' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalLog.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\DataFeatureRemovalLog' => __DIR__ . '/../..' . '/src/Helper/DataFeatureRemovalLog.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Helper\\ExecutionLimits' => __DIR__ . '/../..' . '/src/Helper/ExecutionLimits.php',
|
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataCleanupService' => __DIR__ . '/../..' . '/src/Service/DataCleanupService.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataCleanupService' => __DIR__ . '/../..' . '/src/Service/DataCleanupService.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataFeatureRemoverExtensionService' => __DIR__ . '/../..' . '/src/Service/DataFeatureRemoverExtensionService.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Service\\DataFeatureRemoverExtensionService' => __DIR__ . '/../..' . '/src/Service/DataFeatureRemoverExtensionService.php',
|
||||||
'Combodo\\iTop\\DataFeatureRemoval\\Service\\ObjectService' => __DIR__ . '/../..' . '/src/Service/ObjectService.php',
|
'Combodo\\iTop\\DataFeatureRemoval\\Service\\ObjectService' => __DIR__ . '/../..' . '/src/Service/ObjectService.php',
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ if (PHP_VERSION_ID < 50600) {
|
|||||||
echo $err;
|
echo $err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trigger_error(
|
throw new RuntimeException($err);
|
||||||
$err,
|
|
||||||
E_USER_ERROR
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once __DIR__ . '/composer/autoload_real.php';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|||||||
@@ -625,6 +625,7 @@ return array(
|
|||||||
'Combodo\\iTop\\Service\\Events\\iEventServiceSetup' => $baseDir . '/sources/Service/Events/iEventServiceSetup.php',
|
'Combodo\\iTop\\Service\\Events\\iEventServiceSetup' => $baseDir . '/sources/Service/Events/iEventServiceSetup.php',
|
||||||
'Combodo\\iTop\\Service\\Import\\CSVImportPageProcessor' => $baseDir . '/sources/Service/Import/CSVImportPageProcessor.php',
|
'Combodo\\iTop\\Service\\Import\\CSVImportPageProcessor' => $baseDir . '/sources/Service/Import/CSVImportPageProcessor.php',
|
||||||
'Combodo\\iTop\\Service\\InterfaceDiscovery\\InterfaceDiscovery' => $baseDir . '/sources/Service/InterfaceDiscovery/InterfaceDiscovery.php',
|
'Combodo\\iTop\\Service\\InterfaceDiscovery\\InterfaceDiscovery' => $baseDir . '/sources/Service/InterfaceDiscovery/InterfaceDiscovery.php',
|
||||||
|
'Combodo\\iTop\\Service\\Limits\\ExecutionLimits' => $baseDir . '/sources/Service/Limits/ExecutionLimits.php',
|
||||||
'Combodo\\iTop\\Service\\Links\\LinkSetDataTransformer' => $baseDir . '/sources/Service/Links/LinkSetDataTransformer.php',
|
'Combodo\\iTop\\Service\\Links\\LinkSetDataTransformer' => $baseDir . '/sources/Service/Links/LinkSetDataTransformer.php',
|
||||||
'Combodo\\iTop\\Service\\Links\\LinkSetModel' => $baseDir . '/sources/Service/Links/LinkSetModel.php',
|
'Combodo\\iTop\\Service\\Links\\LinkSetModel' => $baseDir . '/sources/Service/Links/LinkSetModel.php',
|
||||||
'Combodo\\iTop\\Service\\Links\\LinkSetRepository' => $baseDir . '/sources/Service/Links/LinkSetRepository.php',
|
'Combodo\\iTop\\Service\\Links\\LinkSetRepository' => $baseDir . '/sources/Service/Links/LinkSetRepository.php',
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ return array(
|
|||||||
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
|
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
|
||||||
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
|
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
|
||||||
'Pelago\\Emogrifier\\' => array($vendorDir . '/pelago/emogrifier/src'),
|
'Pelago\\Emogrifier\\' => array($vendorDir . '/pelago/emogrifier/src'),
|
||||||
'League\\OAuth2\\Client\\' => array($vendorDir . '/league/oauth2-client/src', $vendorDir . '/league/oauth2-google/src'),
|
'League\\OAuth2\\Client\\' => array($vendorDir . '/league/oauth2-google/src', $vendorDir . '/league/oauth2-client/src'),
|
||||||
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
|
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
|
||||||
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
|
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
|
||||||
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
|
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
|
||||||
|
|||||||
@@ -360,8 +360,8 @@ class ComposerStaticInitfc0e9e9dea11dcbb6272414776c30685
|
|||||||
),
|
),
|
||||||
'League\\OAuth2\\Client\\' =>
|
'League\\OAuth2\\Client\\' =>
|
||||||
array (
|
array (
|
||||||
0 => __DIR__ . '/..' . '/league/oauth2-client/src',
|
0 => __DIR__ . '/..' . '/league/oauth2-google/src',
|
||||||
1 => __DIR__ . '/..' . '/league/oauth2-google/src',
|
1 => __DIR__ . '/..' . '/league/oauth2-client/src',
|
||||||
),
|
),
|
||||||
'GuzzleHttp\\Psr7\\' =>
|
'GuzzleHttp\\Psr7\\' =>
|
||||||
array (
|
array (
|
||||||
@@ -1026,6 +1026,7 @@ class ComposerStaticInitfc0e9e9dea11dcbb6272414776c30685
|
|||||||
'Combodo\\iTop\\Service\\Events\\iEventServiceSetup' => __DIR__ . '/../..' . '/sources/Service/Events/iEventServiceSetup.php',
|
'Combodo\\iTop\\Service\\Events\\iEventServiceSetup' => __DIR__ . '/../..' . '/sources/Service/Events/iEventServiceSetup.php',
|
||||||
'Combodo\\iTop\\Service\\Import\\CSVImportPageProcessor' => __DIR__ . '/../..' . '/sources/Service/Import/CSVImportPageProcessor.php',
|
'Combodo\\iTop\\Service\\Import\\CSVImportPageProcessor' => __DIR__ . '/../..' . '/sources/Service/Import/CSVImportPageProcessor.php',
|
||||||
'Combodo\\iTop\\Service\\InterfaceDiscovery\\InterfaceDiscovery' => __DIR__ . '/../..' . '/sources/Service/InterfaceDiscovery/InterfaceDiscovery.php',
|
'Combodo\\iTop\\Service\\InterfaceDiscovery\\InterfaceDiscovery' => __DIR__ . '/../..' . '/sources/Service/InterfaceDiscovery/InterfaceDiscovery.php',
|
||||||
|
'Combodo\\iTop\\Service\\Limits\\ExecutionLimits' => __DIR__ . '/../..' . '/sources/Service/Limits/ExecutionLimits.php',
|
||||||
'Combodo\\iTop\\Service\\Links\\LinkSetDataTransformer' => __DIR__ . '/../..' . '/sources/Service/Links/LinkSetDataTransformer.php',
|
'Combodo\\iTop\\Service\\Links\\LinkSetDataTransformer' => __DIR__ . '/../..' . '/sources/Service/Links/LinkSetDataTransformer.php',
|
||||||
'Combodo\\iTop\\Service\\Links\\LinkSetModel' => __DIR__ . '/../..' . '/sources/Service/Links/LinkSetModel.php',
|
'Combodo\\iTop\\Service\\Links\\LinkSetModel' => __DIR__ . '/../..' . '/sources/Service/Links/LinkSetModel.php',
|
||||||
'Combodo\\iTop\\Service\\Links\\LinkSetRepository' => __DIR__ . '/../..' . '/sources/Service/Links/LinkSetRepository.php',
|
'Combodo\\iTop\\Service\\Links\\LinkSetRepository' => __DIR__ . '/../..' . '/sources/Service/Links/LinkSetRepository.php',
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ if ($issues) {
|
|||||||
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
trigger_error(
|
throw new \RuntimeException(
|
||||||
'Composer detected issues in your platform: ' . implode(' ', $issues),
|
'Composer detected issues in your platform: ' . implode(' ', $issues)
|
||||||
E_USER_ERROR
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
48
sources/Service/Limits/ExecutionLimits.php
Normal file
48
sources/Service/Limits/ExecutionLimits.php
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @copyright Copyright (C) 2010-2026 Combodo SAS
|
||||||
|
* @license http://opensource.org/licenses/AGPL-3.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Combodo\iTop\Service\Limits;
|
||||||
|
|
||||||
|
use utils;
|
||||||
|
|
||||||
|
class ExecutionLimits
|
||||||
|
{
|
||||||
|
private int $iMaxTime;
|
||||||
|
private int $iMaxMemoryPercent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $iMaxDuration Max duration time in s
|
||||||
|
* @param int $iMaxMemoryPercent Max memory percent allowed (0-100)
|
||||||
|
*/
|
||||||
|
public function __construct(int $iMaxDuration = 0, int $iMaxMemoryPercent = 100)
|
||||||
|
{
|
||||||
|
$this->iMaxTime = $iMaxDuration + time();
|
||||||
|
$this->iMaxMemoryPercent = (int)min(max($iMaxMemoryPercent, 0), 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool true when duration is
|
||||||
|
*/
|
||||||
|
public function ShouldStopExecution(): bool
|
||||||
|
{
|
||||||
|
if (($this->iMaxTime != 0) && (time() > $this->iMaxTime)) {
|
||||||
|
\IssueLog::Debug(__METHOD__.' timeout '.time()." (current) > $this->iMaxTime (max)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$iMaxMemoryPercent = (int)min(max($this->iMaxMemoryPercent, 0), 100);
|
||||||
|
$iMemory = memory_get_usage(true);
|
||||||
|
$iMaxMemory = utils::GetMemoryLimit() * $iMaxMemoryPercent / 100;
|
||||||
|
if ($iMemory > $iMaxMemory) {
|
||||||
|
\IssueLog::Debug(__METHOD__." Memory limit $iMemory (current) > $iMaxMemory (max)");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user