* @since 0.1 */ class MoleController extends Controller { /** * Запуск всех агентов для проекта yii из mole_task * @return int Exit code */ public function actionIndex() { $filePatch = __DIR__.'/../runtime/lock.lock'; if(!file_exists($filePatch)) { $fp = fopen($filePatch, "w"); fwrite($fp, ""); fclose($fp); } $file = fopen($filePatch, 'r+'); if (flock($file, LOCK_EX | LOCK_NB)) { $model = new MoleTask; $tasks = $model->getAllTask(); foreach ($tasks as $task) { try { $task->dateStart = date('Y-m-d H:i:s'); $task->save(); $class = 'app\commands\\' . $task->controller; if (class_exists($class)) { $control = new $class($task->controller, 'product'); $control->actionIndex(unserialize($task->params)); } $task->dateEnd = date('Y-m-d H:i:s'); $task->completed = 1; $task->save(); } catch (\yii\elasticsearch\Exception $ex) { $task->dateStart = null; $task->save(); print_r($ex); } } } return ExitCode::OK; } }