/** * Inspeciona o arquivo de configuração do work manager para atualizar algumas configurações. * * @return bool */ private function inspect() { $table = Table::getInstance(); $table->loadInformation(); $config = $table->getConfig(); if ($config['active'] == false) { return false; } $amount = memory_get_usage(true); $megabytes = $amount / 1024 / 1024; $table->updateMemoryUsage($megabytes); //verificando se a memória atual esta´dentro do limite imposto pela configuração da aplicação $limit_memory = Config::getInstance()->get('app.work-limit-memory'); if ($megabytes >= $limit_memory) { $table->turnOff(); exec('php anna job:up'); } $config = null; $table = null; $amount = null; unset($config); unset($table); unset($amount); return true; }
private function warmUp() { $table = Table::getInstance(); $workers = $table->getWorkers(); $now = time(); foreach ($workers as $worker) { if ($worker['active'] == true) { $exec_time = strtotime($worker['next_run']); $active_in = strtotime($worker['active_in']); if ($now >= $exec_time && $now >= $active_in) { $this->doWork($worker); //em outro processo em background; $worker['times_performed'] = (int) $worker['times_performed'] + 1; $worker['last_run'] = $worker['next_run']; if ($worker['limit_performation']) { if ($worker['times_performed'] >= $worker['limit_performation']) { $worker['active'] = false; } } if ($worker['active'] == true) { $next_date = new \Datetime('now'); $next_run = $this->getNextExecutionTime($worker['string_timed'], $next_date)->format('Y-m-d H:i:s'); $worker['next_run'] = $next_run; } $table->updateWorker($worker); } } } }
protected function execute(InputInterface $input, OutputInterface $output) { $table = Table::getInstance(); $config = $table->getConfig(); if ($config['active'] == true) { $output->writeln('Servico de workers ja estao ativos, finalize o servico antes de inicialo novamente.'); return; } $table->turnOn(); $os = explode(' ', php_uname())[0]; if ($os == 'Windows') { $WshShell = new \COM('WScript.Shell'); $WshShell->Run('php anna job:observer', 0, false); } else { exec('php anna job:observer &'); } $output->writeln('Servico de workers acionado com sucesso.'); }
protected function execute(InputInterface $input, OutputInterface $output) { Table::getInstance()->turnOff(); $output->writeln('Finalizando o servico de workers'); }