/** * @param bool $onlyregister - true- rejestruje w beanstalk że trzeba jak najszybciej odpalić ten proces, false, wykonuje logikę samego procesu * * @throws Exception */ public function checkFiles($onlyregister = false) { if ($onlyregister) { $s = App::getServiceBeanstalkd(); try { $j = $s->reserve(null, false); $data = $j['data']; if (isset($data['mode']) && $data['mode'] === 'checkfile') { echo 'esc1'; return; } } catch (BeanstalkdException $ex) { if ($ex->getCode() !== BeanstalkdException::EMPTYTUBE_ERROR) { throw $ex; } } $s->put(array('mode' => 'checkfile'), $ttr = 0, $delay = 0, $pri = 1); return; } foreach (array(App::getConfig('clxsource.storageidcsv') => App::getConfig('clxsource.etltmpidcsv'), App::getConfig('clxsource.storagewarmcsv') => App::getConfig('clxsource.etltmpwarmcsv'), App::getConfig('clxsource.storagepbindjson') => App::getConfig('clxsource.etlpbindjson')) as $file => $target) { UtilFilesystem::checkIfFileExistOrICanCreate($file, true); $p = new Process("wc -l {$file} | awk '{print \$1}'"); $sek = 5; $p->setTimeout($sek); try { $p->run(); } catch (ProcessTimedOutException $ex) { throw new Exception("Zliczanie linii w pliku '{$file}' przekroczyło dozwolony czas {$sek} sekund"); } if (!$p->isSuccessful()) { throw new Exception("Coś poszło nie tak podczas zliczania linii w pliku '{$file}'"); } if ((int) $p->getOutput() > static::MAXLINESINFILE) { $target = str_replace('*', date('Y_m_d_H_i_s'), $target); $dir = dirname($target); if (UtilFilesystem::checkDir($dir, true)) { echo "\nPrzenoszę plik {$file}"; rename($file, $target); touch($file); } } else { $file = pathinfo($file, PATHINFO_BASENAME); echo "\n'{$file}' don't move"; } } }
public function transport($file, $data) { $c = App::getConfig('project.cdnwebdir'); $webdir = $c . dirname($data['path']); UtilFilesystem::mkDir($webdir, true); $target = $c . $data['path']; copy($file, $target); if (file_exists($target)) { echo "Plik {$target} został utworzony" . PHP_EOL; } else { throw new Exception("Nie utworzono pliku {$target}"); } }