->one();
if ($scriptLauncherLog && $scriptLauncherLog['active'] == 1 && $scriptLauncherLog['status'] == 1) {
//$task = json_decode($scriptLauncherLog['context'], true );
+ // $cache->delete($cacheKey);
$this->stdout("Задача уже запущена {$task['startTime']}\n");
return ExitCode::OK;
}
$log->year = (int)$task['year'];
$log->month = (int)$task['month'];
$log->active = 1;
+ $log->progress = 0;
$log->status = 1;
$log->date_start = date('Y-m-d H:i:s');
if (!$log->save()) {
$this->stdout("Сохранена автопланограмма для магазина {$storeId}\n", BaseConsole::FG_GREEN);
-
$task['status'] = 'done';
$task['progress'] = 100;
$cache->set($cacheKey, $task);
+ $log->context = json_encode($task, JSON_UNESCAPED_UNICODE);
$log->message = 'Finished successfully';
$log->progress = 100;
$log->active = 0;
+ $log->progress = 100;
$log->date_finish = date('Y-m-d H:i:s');
$log->status = 2;
if (!$log->save()) {
Yii::error(json_encode($log->getErrors(), JSON_UNESCAPED_UNICODE));
LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $log->getErrors()], JSON_UNESCAPED_UNICODE));
}
-
+ $cache->delete($cacheKey);
$this->stdout("Расчет для магазина {$storeId} закончен\n");
return ExitCode::OK;
Yii::error(json_encode($log->getErrors(), JSON_UNESCAPED_UNICODE));
LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $log->getErrors()], JSON_UNESCAPED_UNICODE));
}
- Yii::$app->cache->delete("apRecalculateTask");
+ $cache->delete($cacheKey);
$this->stderr("Ошибка в ходе расчета: {$e->getMessage()}\n");
return ExitCode::UNSPECIFIED_ERROR;
}
->asArray()
->limit(1)
->one();
- if ($scriptLauncherLog && $scriptLauncherLog['active'] == 1) {
+ if ($scriptLauncherLog && $scriptLauncherLog['active'] == 1 && $scriptLauncherLog['status'] == 1) {
return $this->asJson(['status' => 'running' ]);
} else {
$taskName = "apRecalculateTask";
public function actionCheckTask()
{
$task = Yii::$app->cache->get('apRecalculateTask');
- if ($task && $task['status'] === 'done') {
- Yii::$app->cache->delete("apRecalculateTask");
- }
if (!$task) {
+ $scriptLauncherLog = ScriptLauncherLog::find()
+ ->andWhere(['name' => "taskApRecalculate"])
+ ->orderBy(['created_at' => SORT_DESC])
+ ->asArray()
+ ->limit(1)
+ ->one();
+
+ if (!$scriptLauncherLog) {
+ return $this->asJson(['status' => 'not_found']);
+ }
- return $this->asJson(['status' => 'not_found']);
+ $dateFinish = $scriptLauncherLog['date_finish'];
+ $ageSeconds = $dateFinish
+ ? time() - strtotime($dateFinish)
+ : null;
+
+
+ if ($dateFinish === null || $ageSeconds <= 5) {
+ $task = json_decode($scriptLauncherLog['context'], true);
+ } else {
+ return $this->asJson(['status' => 'not_found']);
+ }
}
return $this->asJson([
<h1><?= $stores[$model->store_id]?></h1>
<div id="changes-count" class="fs-6"></div>
<div id="changes" style="display:none;"></div>
+ <div id="changes-hint" style="display:none;" class="fs-6 mt-3 text-danger" >После внесения всех изменений нажмите на кнопку
+ <br>"Пересчитать автопланограмму"</div>
<?= Html::button('Пересчитать автопланограмму', [
'class' => 'btn btn-success m-2',
'disabled' => true,
}
});
- $('#changes-hint').remove();
- $('#changes').after('<div id="changes-hint" class="fs-6 mt-3 text-danger" >После внесения всех изменений нажмите на кнопку\n' +
- '<br>"Пересчитать автопланограмму"</div>');
+ $('#changes-hint').show();
+ $('#changes').show();
+ $('#changes-count').show();
changesBox.html(`<ul>${listItems}</ul>`).hide();
changesCount.html(`Были внесены изменения (число изменений) - ${count} <button id="show-changes" class="btn btn-link">Подробнее</button>`);
language: data_table_language
});
const store_id = $('#selected-store').val();
- const changes = JSON.parse(localStorage.getItem('planChanges') || '{}');
+ const changesRaw = localStorage.getItem('planChanges');
+ const changes = changesRaw ? JSON.parse(changesRaw) : {};
- if (store_id && changes[store_id]) {
- updateChangesLog(store_id);
- $('#rebuild').prop('disabled', false);
- $('#delete').prop('disabled', false);
+ const hasChanges = changes[store_id]
+ && Object.keys(changes[store_id]).length > 0;
+
+ if (hasChanges) {
+ updateChangesLog(store_id);
+ $('#rebuild, #delete, #filter-btn').prop('disabled', false);
+ $('#changes-hint,#changes,#changes-count').show();
+ } else {
+ $('#rebuild, #delete').prop('disabled', true);
+ $('#changes-hint,#changes,#changes-count').hide();
}
$('#delete').on('click', function (event) {
$('#delete').prop('disabled', true);
$('#filter-btn').prop('disabled', true);
$('#changes-hint').hide();
+ $('#changes').hide();
+ $('#changes-count').hide();
$('#categoryPlan').addClass('block_table');
}
if (data.status === 'done') {
taskPollInterval = null;
localStorage.removeItem('planChanges');
$('#categoryPlan').removeClass('block_table');
- $('#rebuild').prop('disabled', false).text('Пересчитать автопланограмму');
- $('#delete').prop('disabled', false);
- $('#changes-hint').remove();
+ $('#rebuild').prop('disabled', true).text('Пересчитать автопланограмму');
+ $('#delete').prop('disabled', true);
+ $('#changes-hint').hide();
+ $('#changes-count').hide();
$('#changes').hide();
$('#filter-btn').prop('disabled', false);
alert('Персчет автопланнограммы успешно завершен');