Skip to content

Commit

Permalink
AbeilleLQI: lock file renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Jun 14, 2024
1 parent f7cc74f commit 0bbd2db
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
10 changes: 4 additions & 6 deletions core/class/Abeille.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,10 @@ public static function deamon_start_cleanup() {
message::removeAll('Abeille');

// Remove any remaining temporary files
for ($gtwId = 1; $gtwId <= $GLOBALS['maxGateways']; $gtwId++) {
$lockFile = jeedom::getTmpFolder('Abeille').'/AbeilleLQI-Abeille'.$gtwId.'.json.lock';
if (file_exists($lockFile)) {
unlink($lockFile);
log::add('Abeille', 'debug', 'deamon_start_cleanup(): Removed '.$lockFile);
}
$lockFile = jeedom::getTmpFolder('Abeille').'/AbeilleLQI.lock';
if (file_exists($lockFile)) {
unlink($lockFile);
log::add('Abeille', 'debug', 'deamon_start_cleanup(): Removed '.$lockFile);
}

// Clear zigate IEEE status to detect any port switch.
Expand Down
38 changes: 21 additions & 17 deletions core/php/AbeilleLQI.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,26 @@ function interrogateEq($netName, $addr, $eqIdx) {
$zgEnd = $zgId;
}

$tmpDir = jeedom::getTmpFolder("Abeille"); // Jeedom temp directory

// Checking if LQI collector is already running
$lockFile = $tmpDir."/AbeilleLQI.lock";
if (file_exists($lockFile)) {
$content = file_get_contents($lockFile);
logMessage("", "Lock content: '${content}'");
if (substr($content, 0, 4) != "done") {
exec("pgrep -a php | grep AbeilleLQI", $running);
if (sizeof($running) != 0) {
echo 'ERROR: Collect already ongoing';
logMessage("", "LQI collect already ongoing (lock file found) => collect canceled");
exit;
} else {
logMessage("", "Previous LQI collect crashed. Removing lock file.");
unlink($lockFile);
}
}
}

// Collecting known equipments list
logMessage("", "Known Jeedom equipments:");
$eqLogics = eqLogic::byType('Abeille');
Expand All @@ -465,7 +485,6 @@ function interrogateEq($netName, $addr, $eqIdx) {
$queueParserToLQIMax = $abQueues["parserToLQI"]["max"];
msgFromParserFlush(); // Flush the queue if not empty

$tmpDir = jeedom::getTmpFolder("Abeille"); // Jeedom temp directory

for ($zgId = $zgStart; $zgId <= $zgEnd; $zgId++) {
if (config::byKey('ab::gtwEnabled'.$zgId, 'Abeille', 'N') != 'Y') {
Expand All @@ -475,22 +494,7 @@ function interrogateEq($netName, $addr, $eqIdx) {

$netName = "Abeille".$zgId; // Abeille network
$newDataFile = $tmpDir."/AbeilleLQI-".$netName.".json"; // New format, replacing 'AbeilleLQI_MapDataAbeilleX.json'
$lockFile = $newDataFile.".lock";
if (file_exists($lockFile)) {
$content = file_get_contents($lockFile);
logMessage("", $netName." lock content: '".$content."'");
if (substr($content, 0, 4) != "done") {
exec("pgrep -a php | grep AbeilleLQI", $running);
if (sizeof($running) != 0) {
echo 'ERROR: Collect already ongoing';
logMessage("", "LQI collect already ongoing (lock file found) => collect canceled");
exit;
} else {
logMessage("", "Previous LQI collect crashed. Removing lock file.");
unlink($lockFile);
}
}
}

$nbwritten = file_put_contents($lockFile, "init");
if ($nbwritten < 1) {
unlink($lockFile);
Expand Down
2 changes: 1 addition & 1 deletion desktop/js/AbeilleNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function trackLQICollectStatus(_autoUpdate, zgId) {
url: "/plugins/Abeille/core/ajax/AbeilleFiles.ajax.php",
data: {
action: "getTmpFile",
file: "AbeilleLQI-Abeille" + zgId + ".json.lock",
file: "AbeilleLQI.lock",
},
dataType: "json",
global: false,
Expand Down
2 changes: 1 addition & 1 deletion desktop/modal/AbeilleRefreshLQI.modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function analysisProgress() {
url: "/plugins/Abeille/core/ajax/AbeilleFiles.ajax.php",
data: {
action: 'getTmpFile',
file : "AbeilleLQI-Abeille1.json.lock",
file : "AbeilleLQI.lock",
},
dataType: "json",
global: false,
Expand Down
3 changes: 1 addition & 2 deletions desktop/php/AbeilleNetworkMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ function refreshLqiProgress() {
url: "/plugins/Abeille/core/ajax/AbeilleFiles.ajax.php",
data: {
action: 'getTmpFile',
// file : "AbeilleLQI_MapData"+Ruche+".json.lock",
file : "AbeilleLQI-"+Ruche+".json.lock",
file : "AbeilleLQI.lock",
},
dataType: "json",
global: false,
Expand Down
1 change: 1 addition & 0 deletions docs/fr_FR/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Modèles TRAFRIbulbxxx: Mises-à-jour.
- Assistant de découverte: Ajout 'profile ID' + 'device ID'.
- Réparation: Améliorations pour support 'profile ID' + 'device ID'.
- Interne: 'AbeilleLQI-AbeilleX.json.lock' => 'AbeilleLQI.lock'

## 240610-BETA-1

Expand Down

0 comments on commit 0bbd2db

Please sign in to comment.