Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions app/notifier/scripts/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function __construct(
$this->_lockFile = DOCUMENT_ROOT."/var/.lock";

$this->_lock();
$this->_running = true;

$this->_running = true;
$this->_logger->info("[Pid ".getmypid()."] Vérification des alertes.");

$this->_mailer = new PHPMailer($exceptions=true);
Expand Down Expand Up @@ -129,15 +128,15 @@ public function check()

$baseurl = $this->_config->get("general", "baseurl", "");

foreach ($users AS $user) {
if ($storageType == "db") {
foreach ($users AS $user) {
if ($storageType == "db") {
$storage = new \App\Storage\Db\Alert($this->_userStorage->getDbConnection(), $user);
$this->_logger->info("[Pid ".getmypid()."] USER : ".$user->getUsername());
} else {
$this->_logger->info("[Pid ".getmypid()."] USER : ".$user->getUsername());
} else {
$file = DOCUMENT_ROOT."/var/configs/".$user->getUsername().".csv";
if (!is_file($file)) {
continue;
}
}
$storage = new \App\Storage\File\Alert($file);
$this->_logger->info("[Pid ".getmypid()."] USER : ".$user->getUsername()." (".$file.")");
}
Expand Down Expand Up @@ -539,8 +538,16 @@ protected function _checkConnection()

protected function _lock()
{


if (is_file($this->_lockFile)) {
$content = file_get_contents($this->_lockFile);
//on vérifie que le pid existe vraiment
if(posix_kill(explode("\n",$content)[1], 0)){
throw new Exception("Un processus est en cours d'exécution.");
}else{
Logger::getLogger("main")->info("Le précédent process s'est interrompu de manière anormale.");
}
}
file_put_contents($this->_lockFile, time()."\n".getmypid());
return $this;
Expand All @@ -565,17 +572,12 @@ protected function _lock()
return;
}

try {
$main = new Main($config, $client, $userStorage);
try {
$main = new Main($config, $client, $userStorage);
} catch (\Exception $e) {
Logger::getLogger("main")->info($e->getMessage());
return;
}
Logger::getLogger("main")->info($e->getMessage());
return;
}

$main->check();
$main->shutdown();