mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-02 19:33:14 +03:00
Clearing CURRENT_TASK on JobManager shutdown, remove CONTEXT_ALL and use global values instead
This commit is contained in:
parent
f2a96e92d1
commit
66e678f50c
@ -55,6 +55,7 @@ function retailcrmCliInterruptHandler($signo)
|
|||||||
print_r($signo, true)
|
print_r($signo, true)
|
||||||
));
|
));
|
||||||
RetailcrmCli::clearCurrentJob(null);
|
RetailcrmCli::clearCurrentJob(null);
|
||||||
|
RetailcrmJobManager::clearCurrentJob(null);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,10 +113,6 @@ class RetailcrmCli
|
|||||||
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
$jobName = isset($options['j']) ? $options['j'] : (isset($options['job']) ? $options['job'] : null);
|
||||||
$shopId = isset($options['s']) ? $options['s'] : (isset($options['shop']) ? $options['shop'] : null);
|
$shopId = isset($options['s']) ? $options['s'] : (isset($options['shop']) ? $options['shop'] : null);
|
||||||
|
|
||||||
if (Shop::isFeatureActive()) {
|
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($options['reset-job-manager'])) {
|
if (isset($options['reset-job-manager'])) {
|
||||||
$this->resetJobManager();
|
$this->resetJobManager();
|
||||||
} elseif (isset($options['reset-all'])) {
|
} elseif (isset($options['reset-all'])) {
|
||||||
@ -170,10 +166,6 @@ class RetailcrmCli
|
|||||||
$result ? 'true' : 'false'
|
$result ? 'true' : 'false'
|
||||||
));
|
));
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
if (Shop::isFeatureActive()) {
|
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($exception instanceof RetailcrmJobManagerException && $exception->getPrevious() instanceof \Exception) {
|
if ($exception instanceof RetailcrmJobManagerException && $exception->getPrevious() instanceof \Exception) {
|
||||||
$this->printStack($exception->getPrevious());
|
$this->printStack($exception->getPrevious());
|
||||||
} else {
|
} else {
|
||||||
@ -183,10 +175,6 @@ class RetailcrmCli
|
|||||||
self::clearCurrentJob($jobName);
|
self::clearCurrentJob($jobName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shop::isFeatureActive()) {
|
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($result) && $result) {
|
if (isset($result) && $result) {
|
||||||
self::clearCurrentJob($jobName);
|
self::clearCurrentJob($jobName);
|
||||||
}
|
}
|
||||||
@ -327,7 +315,7 @@ class RetailcrmCli
|
|||||||
*/
|
*/
|
||||||
public static function setCurrentJob($job)
|
public static function setCurrentJob($job)
|
||||||
{
|
{
|
||||||
return (bool) Configuration::updateValue(self::CURRENT_TASK_CLI, $job);
|
return (bool) Configuration::updateGlobalValue(self::CURRENT_TASK_CLI, $job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -337,7 +325,7 @@ class RetailcrmCli
|
|||||||
*/
|
*/
|
||||||
public static function getCurrentJob()
|
public static function getCurrentJob()
|
||||||
{
|
{
|
||||||
return (string) Configuration::get(self::CURRENT_TASK_CLI);
|
return (string) Configuration::getGlobalValue(self::CURRENT_TASK_CLI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,10 +108,6 @@ class RetailcrmJobManager
|
|||||||
$current = date_create('now');
|
$current = date_create('now');
|
||||||
$lastRuns = array();
|
$lastRuns = array();
|
||||||
|
|
||||||
if (Shop::isFeatureActive()) {
|
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$lastRuns = static::getLastRuns();
|
$lastRuns = static::getLastRuns();
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
@ -176,10 +172,6 @@ class RetailcrmJobManager
|
|||||||
$lastRuns[$job] = new \DateTime('now');
|
$lastRuns[$job] = new \DateTime('now');
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
if (Shop::isFeatureActive()) {
|
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($exception instanceof RetailcrmJobManagerException
|
if ($exception instanceof RetailcrmJobManagerException
|
||||||
&& $exception->getPrevious() instanceof \Exception
|
&& $exception->getPrevious() instanceof \Exception
|
||||||
) {
|
) {
|
||||||
@ -201,10 +193,6 @@ class RetailcrmJobManager
|
|||||||
self::clearCurrentJob($job);
|
self::clearCurrentJob($job);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Shop::isFeatureActive()) {
|
|
||||||
Shop::setContext(Shop::CONTEXT_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($result) && $result) {
|
if (isset($result) && $result) {
|
||||||
self::clearCurrentJob($job);
|
self::clearCurrentJob($job);
|
||||||
}
|
}
|
||||||
@ -233,7 +221,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
private static function getLastRuns()
|
private static function getLastRuns()
|
||||||
{
|
{
|
||||||
$lastRuns = json_decode((string)Configuration::get(self::LAST_RUN_NAME), true);
|
$lastRuns = json_decode((string)Configuration::getGlobalValue(self::LAST_RUN_NAME), true);
|
||||||
|
|
||||||
if (json_last_error() != JSON_ERROR_NONE) {
|
if (json_last_error() != JSON_ERROR_NONE) {
|
||||||
$lastRuns = array();
|
$lastRuns = array();
|
||||||
@ -280,7 +268,7 @@ class RetailcrmJobManager
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration::updateValue(self::LAST_RUN_NAME, (string)json_encode($lastRuns));
|
Configuration::updateGlobalValue(self::LAST_RUN_NAME, (string)json_encode($lastRuns));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,7 +329,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function setCurrentJob($job)
|
public static function setCurrentJob($job)
|
||||||
{
|
{
|
||||||
return (bool)Configuration::updateValue(self::CURRENT_TASK, $job);
|
return (bool)Configuration::updateGlobalValue(self::CURRENT_TASK, $job);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -351,7 +339,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
public static function getCurrentJob()
|
public static function getCurrentJob()
|
||||||
{
|
{
|
||||||
return (string)Configuration::get(self::CURRENT_TASK);
|
return (string)Configuration::getGlobalValue(self::CURRENT_TASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -430,6 +418,10 @@ class RetailcrmJobManager
|
|||||||
{
|
{
|
||||||
if (is_callable(self::$customShutdownHandler)) {
|
if (is_callable(self::$customShutdownHandler)) {
|
||||||
call_user_func_array(self::$customShutdownHandler, array($error));
|
call_user_func_array(self::$customShutdownHandler, array($error));
|
||||||
|
} else {
|
||||||
|
if (null !== $error) {
|
||||||
|
self::clearCurrentJob(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RetailcrmLogger::writeCaller(
|
RetailcrmLogger::writeCaller(
|
||||||
@ -591,7 +583,7 @@ class RetailcrmJobManager
|
|||||||
*/
|
*/
|
||||||
private static function isLocked()
|
private static function isLocked()
|
||||||
{
|
{
|
||||||
$inProcess = (bool)Configuration::get(self::IN_PROGRESS_NAME);
|
$inProcess = (bool)Configuration::getGlobalValue(self::IN_PROGRESS_NAME);
|
||||||
$lastRan = static::getLastRun();
|
$lastRan = static::getLastRun();
|
||||||
$lastRanSeconds = $lastRan->format('U');
|
$lastRanSeconds = $lastRan->format('U');
|
||||||
|
|
||||||
@ -615,7 +607,7 @@ class RetailcrmJobManager
|
|||||||
{
|
{
|
||||||
if (!static::isLocked()) {
|
if (!static::isLocked()) {
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, 'Acquiring lock...');
|
RetailcrmLogger::writeDebug(__METHOD__, 'Acquiring lock...');
|
||||||
Configuration::updateValue(self::IN_PROGRESS_NAME, true);
|
Configuration::updateGlobalValue(self::IN_PROGRESS_NAME, true);
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, 'Lock acquired.');
|
RetailcrmLogger::writeDebug(__METHOD__, 'Lock acquired.');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -632,7 +624,7 @@ class RetailcrmJobManager
|
|||||||
private static function unlock()
|
private static function unlock()
|
||||||
{
|
{
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, 'Removing lock...');
|
RetailcrmLogger::writeDebug(__METHOD__, 'Removing lock...');
|
||||||
Configuration::updateValue(self::IN_PROGRESS_NAME, false);
|
Configuration::updateGlobalValue(self::IN_PROGRESS_NAME, false);
|
||||||
RetailcrmLogger::writeDebug(__METHOD__, 'Lock removed.');
|
RetailcrmLogger::writeDebug(__METHOD__, 'Lock removed.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user