|
@@ -17,30 +17,25 @@ class FindBoxService
|
|
|
private $dbHandle;
|
|
private $dbHandle;
|
|
|
private $findBoxCore = null;
|
|
private $findBoxCore = null;
|
|
|
private $labelToBlink;
|
|
private $labelToBlink;
|
|
|
|
|
+ private $ServiceLogger;
|
|
|
|
|
|
|
|
public function __construct()
|
|
public function __construct()
|
|
|
{
|
|
{
|
|
|
global $f3;
|
|
global $f3;
|
|
|
|
|
+
|
|
|
|
|
+ $this->ServiceLogger = new \Log('ServiceLogger.log');
|
|
|
|
|
+
|
|
|
$this->dbHandle = $f3->get('DB');
|
|
$this->dbHandle = $f3->get('DB');
|
|
|
while ($this->findBoxCore == null)
|
|
while ($this->findBoxCore == null)
|
|
|
try {
|
|
try {
|
|
|
$this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
|
|
$this->findBoxCore = new FindBoxCoreSystem(...array_values($f3->get('CORE.fb')));
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
- $this->log2console("Can't find FindBoxCore, retry in 1 second..\n");
|
|
|
|
|
- ob_flush();
|
|
|
|
|
- flush();
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Can't find FindBoxCore, retry in 1 second..", 'd/m/Y H:i:s');
|
|
|
sleep(1);
|
|
sleep(1);
|
|
|
}
|
|
}
|
|
|
$this->labelToBlink = [];
|
|
$this->labelToBlink = [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function log2console(string $msg)
|
|
|
|
|
- {
|
|
|
|
|
- echo '[' . date("d/m/Y H:i:s") . "] $msg";
|
|
|
|
|
- ob_flush();
|
|
|
|
|
- flush();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private function updateServiceStatus()
|
|
private function updateServiceStatus()
|
|
|
{
|
|
{
|
|
|
$qs = new QueueSystem('FindBoxService_isAlive');
|
|
$qs = new QueueSystem('FindBoxService_isAlive');
|
|
@@ -73,7 +68,7 @@ class FindBoxService
|
|
|
$this->labelToBlink[$qCommand->id]->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
|
|
$this->labelToBlink[$qCommand->id]->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
|
|
|
break;
|
|
break;
|
|
|
case Q_DISPLAY:
|
|
case Q_DISPLAY:
|
|
|
- $this->log2console("Change display for label {$qCommand->id} requested\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Change display for label {$qCommand->id} requested", 'd/m/Y H:i:s');
|
|
|
$esl = new SmartESL($this->findBoxCore, [$qCommand->id]);
|
|
$esl = new SmartESL($this->findBoxCore, [$qCommand->id]);
|
|
|
$esl->Display($qCommand->params['templateId'], $qCommand->params['barcode']);
|
|
$esl->Display($qCommand->params['templateId'], $qCommand->params['barcode']);
|
|
|
break;
|
|
break;
|
|
@@ -99,10 +94,10 @@ class FindBoxService
|
|
|
$label->retryForFault--;
|
|
$label->retryForFault--;
|
|
|
// Ho finito il numero di tentativi massimi?
|
|
// Ho finito il numero di tentativi massimi?
|
|
|
if ($label->retryForFault < 0) { // Rimuovo dalla coda l'etichetta
|
|
if ($label->retryForFault < 0) { // Rimuovo dalla coda l'etichetta
|
|
|
- $this->log2console("Label {$label->id} fatal error. Removing from queue\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Label {$label->id} fatal error. Removing from queue", 'd/m/Y H:i:s');
|
|
|
unset($this->labelToBlink[$labelId]);
|
|
unset($this->labelToBlink[$labelId]);
|
|
|
} else { // Riprovo al prossimo ciclo
|
|
} else { // Riprovo al prossimo ciclo
|
|
|
- $this->log2console("Label {$label->id} blink error. Try next cycle...\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Label {$label->id} blink error. Try next cycle...", 'd/m/Y H:i:s');
|
|
|
$label->tsLastLongBlink = 0;
|
|
$label->tsLastLongBlink = 0;
|
|
|
}
|
|
}
|
|
|
} else { // A valid label id array is returned
|
|
} else { // A valid label id array is returned
|
|
@@ -111,7 +106,7 @@ class FindBoxService
|
|
|
$label->tsLastLongBlink = time() + 2;
|
|
$label->tsLastLongBlink = time() + 2;
|
|
|
return true;
|
|
return true;
|
|
|
} else { // Retry to blink to next cycle
|
|
} else { // Retry to blink to next cycle
|
|
|
- $this->log2console("Label {$label->id} blink error. Try next cycle...\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Label {$label->id} blink error. Try next cycle...", 'd/m/Y H:i:s');
|
|
|
$label->tsLastLongBlink = 0;
|
|
$label->tsLastLongBlink = 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -128,7 +123,7 @@ class FindBoxService
|
|
|
{
|
|
{
|
|
|
if ($label->operation == Q_SAVEPRODUCT) {
|
|
if ($label->operation == Q_SAVEPRODUCT) {
|
|
|
$this->findBoxCore->SaveProducts($label->id, $label->description, $label->params['dataFields']);
|
|
$this->findBoxCore->SaveProducts($label->id, $label->description, $label->params['dataFields']);
|
|
|
- $this->log2console("Save product {$label->id}\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Save product {$label->id}", 'd/m/Y H:i:s');
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
@@ -141,7 +136,7 @@ class FindBoxService
|
|
|
*/
|
|
*/
|
|
|
public function Main($f3)
|
|
public function Main($f3)
|
|
|
{
|
|
{
|
|
|
- $this->log2console("Starting FindBoxService main loop\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Starting FindBoxService main loop", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
while (true) {
|
|
while (true) {
|
|
|
|
|
|
|
@@ -153,7 +148,7 @@ class FindBoxService
|
|
|
switch ($label->operation) {
|
|
switch ($label->operation) {
|
|
|
|
|
|
|
|
case Q_BLINK_OFF:
|
|
case Q_BLINK_OFF:
|
|
|
- $this->log2console("BlinkOff for label {$label->id} requested\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("BlinkOff for label {$label->id} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
$esl = new SmartESL($this->findBoxCore, [$label->id]);
|
|
$esl = new SmartESL($this->findBoxCore, [$label->id]);
|
|
|
$err = $esl->BlinkOff();
|
|
$err = $esl->BlinkOff();
|
|
@@ -169,7 +164,7 @@ class FindBoxService
|
|
|
// Force exit and blink off if run time script > MAX_BLINK_TIME_SEC
|
|
// Force exit and blink off if run time script > MAX_BLINK_TIME_SEC
|
|
|
$now = time() - $label->tsFirstBlink;
|
|
$now = time() - $label->tsFirstBlink;
|
|
|
if ($now > $f3->get('MAX_BLINK_TIME_SEC')) {
|
|
if ($now > $f3->get('MAX_BLINK_TIME_SEC')) {
|
|
|
- $this->log2console("Stop label {$label->id} for timeout\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Stop label {$label->id} for timeout", 'd/m/Y H:i:s');
|
|
|
$esl = new SmartESL($this->findBoxCore, [$label->id]);
|
|
$esl = new SmartESL($this->findBoxCore, [$label->id]);
|
|
|
$esl->BlinkOff();
|
|
$esl->BlinkOff();
|
|
|
unset($this->labelToBlink[$labelId]);
|
|
unset($this->labelToBlink[$labelId]);
|
|
@@ -183,7 +178,7 @@ class FindBoxService
|
|
|
/** @var QueueCommand $label */
|
|
/** @var QueueCommand $label */
|
|
|
$calcDuration = $label->getBlinkDuration();
|
|
$calcDuration = $label->getBlinkDuration();
|
|
|
if ($blinkEndTime > $calcDuration) {
|
|
if ($blinkEndTime > $calcDuration) {
|
|
|
- $this->log2console("Auto restart blinking for label $label->id\n");
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Auto restart blinking for label $label->id\n", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
$esl = new SmartESL($this->findBoxCore, [$label->id]);
|
|
$esl = new SmartESL($this->findBoxCore, [$label->id]);
|
|
|
$ledParams = $label->params;
|
|
$ledParams = $label->params;
|