|
@@ -20,8 +20,12 @@ class JobManager
|
|
|
/** @var AsyncJobClass[] $jobs */
|
|
/** @var AsyncJobClass[] $jobs */
|
|
|
private $jobs;
|
|
private $jobs;
|
|
|
|
|
|
|
|
- public function __construct()
|
|
|
|
|
|
|
+ /** @var Log $ServiceLogger */
|
|
|
|
|
+ private $ServiceLogger;
|
|
|
|
|
+
|
|
|
|
|
+ public function __construct($ServiceLogger)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->ServiceLogger = $ServiceLogger;
|
|
|
$this->Reset();
|
|
$this->Reset();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -33,11 +37,57 @@ class JobManager
|
|
|
$this->jobs = [];
|
|
$this->jobs = [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function RemoveLabelsFromJobs(array $labelsToRemove)
|
|
|
|
|
|
|
+ private function array_diff_symmetric(array $ar1, array $ar2): array
|
|
|
|
|
+ {
|
|
|
|
|
+ return array_merge(array_diff($ar1, $ar2), array_diff($ar2, $ar1));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function AggregateBlinkByParams()
|
|
|
{
|
|
{
|
|
|
- foreach($this->jobs as $job) {
|
|
|
|
|
- $job->RemoveLabels($labelsToRemove);
|
|
|
|
|
|
|
+ global $f3;
|
|
|
|
|
+
|
|
|
|
|
+ if (count($this->jobs) == 0)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ $uniq = [];
|
|
|
|
|
+ $freeJobs = array_slice($this->jobs, $f3->get('FINDBOXSERVICE.MAX_JOBS'), null, true);
|
|
|
|
|
+
|
|
|
|
|
+ if (count($freeJobs) == 0)
|
|
|
|
|
+ return;
|
|
|
|
|
+ // Get unique jobs with same params
|
|
|
|
|
+ foreach($freeJobs as $k => $jobToFind) {
|
|
|
|
|
+
|
|
|
|
|
+ $parmExists = array_filter($uniq, function ($job) use ($jobToFind) {
|
|
|
|
|
+ return (count($this->array_diff_symmetric($job->getLedParams(), $jobToFind->getLedParams())) === 0);
|
|
|
|
|
+ });
|
|
|
|
|
+ if (count($parmExists) == 0)
|
|
|
|
|
+ $uniq[$k] = $jobToFind;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ foreach($uniq as $jobUniq) {
|
|
|
|
|
+ array_filter($freeJobs, function ($job) use (&$jobUniq) {
|
|
|
|
|
+
|
|
|
|
|
+ // aggregate ids with same params
|
|
|
|
|
+ if (count($this->array_diff_symmetric($jobUniq->getLedParams(), $job->getLedParams())) === 0) {
|
|
|
|
|
+
|
|
|
|
|
+ if (count($this->array_diff_symmetric($job->getLabels(), $jobUniq->getLabels())) === 0)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ $labels = array_unique(array_merge($job->getLabels(), $jobUniq->getLabels()));
|
|
|
|
|
+ $jobUniq->setLabels($labels);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->jobs = array_merge(
|
|
|
|
|
+ array_slice($this->jobs, 0, 1, true),
|
|
|
|
|
+ $uniq
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function count()
|
|
|
|
|
+ {
|
|
|
|
|
+ return count($this->jobs);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -47,11 +97,20 @@ class JobManager
|
|
|
*/
|
|
*/
|
|
|
public function Run(callable $callBack)
|
|
public function Run(callable $callBack)
|
|
|
{
|
|
{
|
|
|
- foreach($this->jobs as $k => $job) {
|
|
|
|
|
- if ($callBack($job) === TRUE)
|
|
|
|
|
|
|
+ global $f3;
|
|
|
|
|
+
|
|
|
|
|
+ if (count($this->jobs) == 0)
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ $jobList = array_slice($this->jobs, 0, $f3->get('FINDBOXSERVICE.MAX_JOBS'), TRUE);
|
|
|
|
|
+
|
|
|
|
|
+ foreach($jobList as $k => $job) {
|
|
|
|
|
+
|
|
|
|
|
+ if ($callBack($job) === TRUE) {
|
|
|
unset($this->jobs[$k]);
|
|
unset($this->jobs[$k]);
|
|
|
- else
|
|
|
|
|
|
|
+ } else
|
|
|
$job->Run();
|
|
$job->Run();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -59,30 +118,19 @@ class JobManager
|
|
|
{
|
|
{
|
|
|
$this->jobs[] = $job;
|
|
$this->jobs[] = $job;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- public function count()
|
|
|
|
|
- {
|
|
|
|
|
- return count($this->jobs);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class AsyncJobClass
|
|
class AsyncJobClass
|
|
|
{
|
|
{
|
|
|
|
|
+ public $Opened;
|
|
|
/** @var integer $retryForFault */
|
|
/** @var integer $retryForFault */
|
|
|
public $retryForFault;
|
|
public $retryForFault;
|
|
|
-
|
|
|
|
|
/** @var Generator $blinkGenerator */
|
|
/** @var Generator $blinkGenerator */
|
|
|
private $blinkGenerator = null;
|
|
private $blinkGenerator = null;
|
|
|
-
|
|
|
|
|
/** @var array|null ledParams */
|
|
/** @var array|null ledParams */
|
|
|
private $ledParams;
|
|
private $ledParams;
|
|
|
-
|
|
|
|
|
- /** @var bool $blinkoff */
|
|
|
|
|
- private $blinkoff = false;
|
|
|
|
|
-
|
|
|
|
|
/** @var array labels */
|
|
/** @var array labels */
|
|
|
private $labels;
|
|
private $labels;
|
|
|
-
|
|
|
|
|
/** @var FindBoxCoreSystem $fb */
|
|
/** @var FindBoxCoreSystem $fb */
|
|
|
private $fb;
|
|
private $fb;
|
|
|
|
|
|
|
@@ -101,6 +149,7 @@ class AsyncJobClass
|
|
|
$this->labels = $labels;
|
|
$this->labels = $labels;
|
|
|
$this->ledParams = $ledParams;
|
|
$this->ledParams = $ledParams;
|
|
|
$this->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
|
|
$this->retryForFault = $f3->get('MAX_RETRY_FOR_FAULT');
|
|
|
|
|
+ $this->Opened = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function __destruct()
|
|
public function __destruct()
|
|
@@ -113,13 +162,15 @@ class AsyncJobClass
|
|
|
|
|
|
|
|
public function Stop($reason)
|
|
public function Stop($reason)
|
|
|
{
|
|
{
|
|
|
|
|
+ $this->Opened = false;
|
|
|
return $this->blinkGenerator->send($reason);
|
|
return $this->blinkGenerator->send($reason);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function RemoveLabels(array $labelsToFind)
|
|
|
|
|
|
|
+ public function RemoveLabels(array $labelsToFind): int
|
|
|
{
|
|
{
|
|
|
- $a = array_diff($this->labels, $labelsToFind);
|
|
|
|
|
- $this->labels = $a;
|
|
|
|
|
|
|
+ $diff = array_diff($this->labels, $labelsToFind);
|
|
|
|
|
+ $this->labels = $diff;
|
|
|
|
|
+ return count($diff);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -155,7 +206,6 @@ class AsyncJobClass
|
|
|
public function BlinkOFF()
|
|
public function BlinkOFF()
|
|
|
{
|
|
{
|
|
|
$esl = new SmartESL($this->fb, $this->labels);
|
|
$esl = new SmartESL($this->fb, $this->labels);
|
|
|
- $this->blinkoff = true;
|
|
|
|
|
$this->blinkGenerator = $esl->AsyncBlinkOff();
|
|
$this->blinkGenerator = $esl->AsyncBlinkOff();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -164,12 +214,14 @@ class AsyncJobClass
|
|
|
*/
|
|
*/
|
|
|
public function isBlinkoff(): bool
|
|
public function isBlinkoff(): bool
|
|
|
{
|
|
{
|
|
|
- return $this->blinkoff;
|
|
|
|
|
|
|
+ return $this->ledParams == null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function GetCurrentValue()
|
|
public function GetCurrentValue()
|
|
|
{
|
|
{
|
|
|
- return $this->blinkGenerator->current();
|
|
|
|
|
|
|
+ $value = $this->blinkGenerator->current();
|
|
|
|
|
+ $this->Opened = !is_array($value);
|
|
|
|
|
+ return $value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function Run()
|
|
public function Run()
|
|
@@ -181,6 +233,14 @@ class AsyncJobClass
|
|
|
{
|
|
{
|
|
|
return !$this->blinkGenerator->valid();
|
|
return !$this->blinkGenerator->valid();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getLedParams(): array
|
|
|
|
|
+ {
|
|
|
|
|
+ return ($this->ledParams == null) ? [] : $this->ledParams;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class FindBoxService
|
|
class FindBoxService
|
|
@@ -203,6 +263,8 @@ class FindBoxService
|
|
|
/** @var JobManager $jobManager */
|
|
/** @var JobManager $jobManager */
|
|
|
private $jobManager;
|
|
private $jobManager;
|
|
|
|
|
|
|
|
|
|
+ private $ts_ms;
|
|
|
|
|
+
|
|
|
public function __construct()
|
|
public function __construct()
|
|
|
{
|
|
{
|
|
|
global $f3;
|
|
global $f3;
|
|
@@ -219,6 +281,8 @@ class FindBoxService
|
|
|
}
|
|
}
|
|
|
$this->labelToBlink = [];
|
|
$this->labelToBlink = [];
|
|
|
|
|
|
|
|
|
|
+ $this->ts_ms = NULL;
|
|
|
|
|
+
|
|
|
$this->qs_Server = new QueueSystem();
|
|
$this->qs_Server = new QueueSystem();
|
|
|
|
|
|
|
|
$this->qs_Server->CreateService();
|
|
$this->qs_Server->CreateService();
|
|
@@ -234,55 +298,80 @@ class FindBoxService
|
|
|
$this->ServiceLogger->write("Starting FindBoxService main loop", 'd/m/Y H:i:s');
|
|
$this->ServiceLogger->write("Starting FindBoxService main loop", 'd/m/Y H:i:s');
|
|
|
$this->ServiceLogger->write("Opening socket listen {$f3->get('FINDBOXSERVICE.PORT')}", 'd/m/Y H:i:s');
|
|
$this->ServiceLogger->write("Opening socket listen {$f3->get('FINDBOXSERVICE.PORT')}", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
- $this->jobManager = new JobManager();
|
|
|
|
|
|
|
+ $this->jobManager = new JobManager($this->ServiceLogger);
|
|
|
|
|
+
|
|
|
while (true) {
|
|
while (true) {
|
|
|
$this->getCurrentQueue();
|
|
$this->getCurrentQueue();
|
|
|
|
|
|
|
|
- foreach($this->labelToBlink as $commandID => &$label) {
|
|
|
|
|
- switch ($label->operation) {
|
|
|
|
|
|
|
+ $isTimeToAggregateCommands = ($this->now_ms() - $this->ts_ms) > $f3->AGGREGATE_TIMEOUT;
|
|
|
|
|
|
|
|
- case QueueCommand::$Q_BLINK_OFF:
|
|
|
|
|
- $labelJ = join(', ', $label->id);
|
|
|
|
|
- $this->ServiceLogger->write("BlinkOff for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
+ if ($isTimeToAggregateCommands && (count($this->labelToBlink) > 0)) {
|
|
|
|
|
|
|
|
- $this->jobManager->RemoveLabelsFromJobs($label->id);
|
|
|
|
|
|
|
+ foreach($this->labelToBlink as $commandID => &$label) {
|
|
|
|
|
+ switch ($label->operation) {
|
|
|
|
|
|
|
|
- // Rimuove il JOB se esiste
|
|
|
|
|
- $asyncBlinkOFF = new AsyncJobClass($this->findBoxCore, $label->id);
|
|
|
|
|
- $asyncBlinkOFF->BlinkOFF();
|
|
|
|
|
- $this->jobManager->add($asyncBlinkOFF);
|
|
|
|
|
|
|
+ case QueueCommand::$Q_BLINK_OFF:
|
|
|
|
|
+ $labelJ = join(', ', $label->id);
|
|
|
|
|
+ $this->ServiceLogger->write("BlinkOff for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
- unset($this->labelToBlink[$commandID]);
|
|
|
|
|
|
|
+ // Rimuove il JOB se esiste
|
|
|
|
|
+ $asyncBlinkOFF = new AsyncJobClass($this->findBoxCore, $label->id);
|
|
|
|
|
+// $asyncBlinkOFF->BlinkOFF();
|
|
|
|
|
+ $this->jobManager->add($asyncBlinkOFF);
|
|
|
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ unset($this->labelToBlink[$commandID]);
|
|
|
|
|
|
|
|
- case QueueCommand::$Q_BLINK_ON:
|
|
|
|
|
- $labelJ = join(', ', $label->id);
|
|
|
|
|
- $this->ServiceLogger->write("BlinkOn for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
|
|
|
- $this->jobManager->RemoveLabelsFromJobs($label->id);
|
|
|
|
|
|
|
+ case QueueCommand::$Q_BLINK_ON:
|
|
|
|
|
+ $labelJ = join(', ', $label->id);
|
|
|
|
|
+ $this->ServiceLogger->write("BlinkOn for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
- $asyncBlink = new AsyncJobClass($this->findBoxCore, $label->id, $label->params);
|
|
|
|
|
- $asyncBlink->BlinkON();
|
|
|
|
|
- $this->jobManager->add($asyncBlink);
|
|
|
|
|
|
|
+ $asyncBlink = new AsyncJobClass($this->findBoxCore, $label->id, $label->params);
|
|
|
|
|
+// $asyncBlink->BlinkON();
|
|
|
|
|
+ $this->jobManager->add($asyncBlink);
|
|
|
|
|
|
|
|
- unset($this->labelToBlink[$commandID]);
|
|
|
|
|
|
|
+ unset($this->labelToBlink[$commandID]);
|
|
|
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ $this->ts_ms = NULL;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// if ($this->jobManager->count() < 1)
|
|
|
|
|
+// continue;
|
|
|
|
|
+
|
|
|
|
|
+ $this->jobManager->AggregateBlinkByParams();
|
|
|
|
|
+
|
|
|
// Async check on JOBS
|
|
// Async check on JOBS
|
|
|
$this->jobManager->Run(function (AsyncJobClass $asyncBlink) {
|
|
$this->jobManager->Run(function (AsyncJobClass $asyncBlink) {
|
|
|
|
|
|
|
|
|
|
+ // Start the JOB
|
|
|
|
|
+ if (!$asyncBlink->Opened) {
|
|
|
|
|
+ if ($asyncBlink->isBlinkoff())
|
|
|
|
|
+ $asyncBlink->BlinkOFF();
|
|
|
|
|
+ else
|
|
|
|
|
+ $asyncBlink->BlinkON();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$err = $asyncBlink->GetCurrentValue(); // Fa scattare il generator e ricava il valore
|
|
$err = $asyncBlink->GetCurrentValue(); // Fa scattare il generator e ricava il valore
|
|
|
|
|
|
|
|
// Response RESTful ricevuta da Findbox Core?
|
|
// Response RESTful ricevuta da Findbox Core?
|
|
|
if (is_array($err)) {
|
|
if (is_array($err)) {
|
|
|
- if ($this->ManageBlinkFaults($asyncBlink, $asyncBlink->getLabels(), $err)) {
|
|
|
|
|
|
|
+ // TODO da controllare perchè sembra che si accumulino array quadrupli
|
|
|
|
|
+ $this->ServiceLogger->write('JobManager->Run: '
|
|
|
|
|
+ . json_encode($asyncBlink->getLabels())
|
|
|
|
|
+ . json_encode($asyncBlink->getLedParams())
|
|
|
|
|
+ . ' err ' . json_encode($err['value']['value']), 'd/m/Y H:i:s');
|
|
|
|
|
+
|
|
|
|
|
+ if ($this->ManageBlinkFaults($asyncBlink, $err)) {
|
|
|
// Remove the JOB
|
|
// Remove the JOB
|
|
|
return TRUE;
|
|
return TRUE;
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ $labelJ = join(', ', $asyncBlink->getLabels());
|
|
|
|
|
+ $this->ServiceLogger->write("Restart BlinkOn/Off for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
+
|
|
|
// Restart JOB if any errors
|
|
// Restart JOB if any errors
|
|
|
if ($asyncBlink->isBlinkoff())
|
|
if ($asyncBlink->isBlinkoff())
|
|
|
$asyncBlink->BlinkOFF();
|
|
$asyncBlink->BlinkOFF();
|
|
@@ -292,9 +381,7 @@ class FindBoxService
|
|
|
}
|
|
}
|
|
|
return FALSE;
|
|
return FALSE;
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -303,6 +390,24 @@ class FindBoxService
|
|
|
/** @var QueueCommand $qCommand */
|
|
/** @var QueueCommand $qCommand */
|
|
|
$this->qs_Server->ServerCheckClientCommands(
|
|
$this->qs_Server->ServerCheckClientCommands(
|
|
|
function ($clientCommands) {
|
|
function ($clientCommands) {
|
|
|
|
|
+
|
|
|
|
|
+ if ($clientCommands->operation == QueueCommand::$Q_BLINK_ON || $clientCommands->operation == QueueCommand::$Q_BLINK_OFF) {
|
|
|
|
|
+
|
|
|
|
|
+ if ($clientCommands->id == null) {
|
|
|
|
|
+ $this->ServiceLogger->write("No labels passed to BLINK_OFF", 'd/m/Y H:i:s');
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ // Remove NULL label_id if present
|
|
|
|
|
+ $clientCommands->id = array_filter($clientCommands->id);
|
|
|
|
|
+
|
|
|
|
|
+ // Start aggregation timer only when first blink on/off is received
|
|
|
|
|
+ if ($this->ts_ms == NULL)
|
|
|
|
|
+ $this->ts_ms = $this->now_ms();
|
|
|
|
|
+
|
|
|
|
|
+ $this->RemoveDuplicateLabels($clientCommands->id);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
switch ($clientCommands->operation) {
|
|
switch ($clientCommands->operation) {
|
|
|
|
|
|
|
|
case QueueCommand::$Q_GETJOBS:
|
|
case QueueCommand::$Q_GETJOBS:
|
|
@@ -319,19 +424,26 @@ class FindBoxService
|
|
|
$this->saveProduct($clientCommands);
|
|
$this->saveProduct($clientCommands);
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
- case QueueCommand::$Q_BLINK_ON:
|
|
|
|
|
case QueueCommand::$Q_BLINK_OFF:
|
|
case QueueCommand::$Q_BLINK_OFF:
|
|
|
// Split blink list by 9 items each array
|
|
// Split blink list by 9 items each array
|
|
|
- if ($clientCommands->id == null) {
|
|
|
|
|
- $this->ServiceLogger->write("No labels passed to BLINK_ON/OFF command code '{$clientCommands->operation}'", 'd/m/Y H:i:s');
|
|
|
|
|
- return NULL;
|
|
|
|
|
- }
|
|
|
|
|
- $idsWithoutNULLs = array_filter($clientCommands->id);
|
|
|
|
|
- $labelsSplitted = array_chunk($idsWithoutNULLs, 9);
|
|
|
|
|
- foreach($labelsSplitted as $labels) {
|
|
|
|
|
- $cmd = clone $clientCommands;
|
|
|
|
|
- $cmd->id = $labels;
|
|
|
|
|
- $this->labelToBlink[rand(0, 60000)] = $cmd;
|
|
|
|
|
|
|
+ $this->SplitArrayIn9Parts($clientCommands);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case QueueCommand::$Q_BLINK_ON:
|
|
|
|
|
+ // filter for blinkon and regroup for jobs that has same blink parameters
|
|
|
|
|
+ $flt = array_filter($this->labelToBlink, function (&$item) use ($clientCommands) {
|
|
|
|
|
+ if ($item->operation != QueueCommand::$Q_BLINK_ON)
|
|
|
|
|
+ return false;
|
|
|
|
|
+ return count(array_diff($item->params, $clientCommands->params)) === 0;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (count($flt) > 0) {
|
|
|
|
|
+ $key = array_keys($flt)[0]; // get first array key name
|
|
|
|
|
+ $flt[$key]->id = array_merge($flt[$key]->id, $clientCommands->id); //merge all label id of all jobs removing duplicates too
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Split blink list by 9 items each array
|
|
|
|
|
+ $this->SplitArrayIn9Parts($clientCommands);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -346,6 +458,31 @@ class FindBoxService
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Return time in milliseconds
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return float
|
|
|
|
|
+ */
|
|
|
|
|
+ private function now_ms()
|
|
|
|
|
+ {
|
|
|
|
|
+ return round(microtime(true) * 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Remove the label already present in blink_on lists
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $labelsToRemove
|
|
|
|
|
+ */
|
|
|
|
|
+ private function RemoveDuplicateLabels(array $labelsToRemove)
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->labelToBlink = array_filter($this->labelToBlink, function (&$item) use ($labelsToRemove) {
|
|
|
|
|
+ if (count(array_intersect($item->id, $labelsToRemove)) > 0) {
|
|
|
|
|
+ $item->id = array_diff($item->id, $labelsToRemove);
|
|
|
|
|
+ }
|
|
|
|
|
+ return count($item->id) > 0; // need to clean empty jobs due to empty label_id
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Send SaveProduct to Label
|
|
* Send SaveProduct to Label
|
|
|
*
|
|
*
|
|
@@ -355,25 +492,36 @@ class FindBoxService
|
|
|
public function saveProduct($label)
|
|
public function saveProduct($label)
|
|
|
{
|
|
{
|
|
|
if ($label->operation == QueueCommand::$Q_SAVEPRODUCT) {
|
|
if ($label->operation == QueueCommand::$Q_SAVEPRODUCT) {
|
|
|
- $this->findBoxCore->SaveProducts($label->id[0], $label->description, $label->params['dataFields']);
|
|
|
|
|
|
|
+ $retSave = $this->findBoxCore->SaveProducts($label->id[0], $label->description, $label->params['dataFields']);
|
|
|
$labelsJ = join(', ', $label->id);
|
|
$labelsJ = join(', ', $label->id);
|
|
|
- $this->ServiceLogger->write("Save product {$labelsJ}", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
+ $this->ServiceLogger->write("Save product {$labelsJ} RET_CODE= {$retSave['value']['code']} RET_VALUE= {$retSave['value']['value']}", 'd/m/Y H:i:s');
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function SplitArrayIn9Parts(QueueCommand $command)
|
|
|
|
|
+ {
|
|
|
|
|
+ // Split blink list by 9 items each array
|
|
|
|
|
+ $labelsSplitted = array_chunk($command->id, 9);
|
|
|
|
|
+ foreach($labelsSplitted as $labels) {
|
|
|
|
|
+ $cmd = clone $command;
|
|
|
|
|
+ $cmd->id = $labels;
|
|
|
|
|
+ $this->labelToBlink[rand(0, 60000)] = $cmd;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @param AsyncJobClass $job
|
|
* @param AsyncJobClass $job
|
|
|
* @param array $labels
|
|
* @param array $labels
|
|
|
* @param $fbError
|
|
* @param $fbError
|
|
|
* @return bool true if no error, false if error
|
|
* @return bool true if no error, false if error
|
|
|
*/
|
|
*/
|
|
|
- private function ManageBlinkFaults(AsyncJobClass &$job, array $labels, $fbError): bool
|
|
|
|
|
|
|
+ private function ManageBlinkFaults(AsyncJobClass &$job, $fbError): bool
|
|
|
{
|
|
{
|
|
|
$labelResponses = $this->findBoxCore->getLabelsFromResponse($fbError);
|
|
$labelResponses = $this->findBoxCore->getLabelsFromResponse($fbError);
|
|
|
if ($labelResponses === NULL) {
|
|
if ($labelResponses === NULL) {
|
|
|
- $labelJ = join(', ', $labels);
|
|
|
|
|
|
|
+ $labelJ = join(', ', $job->getLabels());
|
|
|
$this->ServiceLogger->write("Label(s) {$labelJ} error removed from queue: {$fbError['value']['value']}", 'd/m/Y H:i:s');
|
|
$this->ServiceLogger->write("Label(s) {$labelJ} error removed from queue: {$fbError['value']['value']}", 'd/m/Y H:i:s');
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -391,7 +539,7 @@ class FindBoxService
|
|
|
|
|
|
|
|
// Ho finito il numero di tentativi massimi?
|
|
// Ho finito il numero di tentativi massimi?
|
|
|
if ($job->retryForFault < 0) { // Rimuovo dalla coda l'etichetta
|
|
if ($job->retryForFault < 0) { // Rimuovo dalla coda l'etichetta
|
|
|
- $labelJ = join(', ', $labels);
|
|
|
|
|
|
|
+ $labelJ = join(', ', $job->getLabels());
|
|
|
$this->ServiceLogger->write("Label(s) {$labelJ} fatal error. Removing from queue", 'd/m/Y H:i:s');
|
|
$this->ServiceLogger->write("Label(s) {$labelJ} fatal error. Removing from queue", 'd/m/Y H:i:s');
|
|
|
return true;
|
|
return true;
|
|
|
} else { // Riprovo al prossimo ciclo
|
|
} else { // Riprovo al prossimo ciclo
|