|
@@ -21,6 +21,14 @@ class JobManager
|
|
|
private $jobs;
|
|
private $jobs;
|
|
|
|
|
|
|
|
public function __construct()
|
|
public function __construct()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->Reset();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ * Reset Job Manager and clear active queue
|
|
|
|
|
+ */
|
|
|
|
|
+ public function Reset()
|
|
|
{
|
|
{
|
|
|
$this->jobs = [];
|
|
$this->jobs = [];
|
|
|
}
|
|
}
|
|
@@ -51,6 +59,11 @@ class JobManager
|
|
|
{
|
|
{
|
|
|
$this->jobs[] = $job;
|
|
$this->jobs[] = $job;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public function count()
|
|
|
|
|
+ {
|
|
|
|
|
+ return count($this->jobs);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class AsyncJobClass
|
|
class AsyncJobClass
|
|
@@ -187,6 +200,9 @@ class FindBoxService
|
|
|
/** @var QueueSystem $qs_Server */
|
|
/** @var QueueSystem $qs_Server */
|
|
|
private $qs_Server;
|
|
private $qs_Server;
|
|
|
|
|
|
|
|
|
|
+ /** @var JobManager $jobManager */
|
|
|
|
|
+ private $jobManager;
|
|
|
|
|
+
|
|
|
public function __construct()
|
|
public function __construct()
|
|
|
{
|
|
{
|
|
|
global $f3;
|
|
global $f3;
|
|
@@ -218,7 +234,7 @@ 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');
|
|
|
|
|
|
|
|
- $jobManager = new JobManager();
|
|
|
|
|
|
|
+ $this->jobManager = new JobManager();
|
|
|
while (true) {
|
|
while (true) {
|
|
|
$this->getCurrentQueue();
|
|
$this->getCurrentQueue();
|
|
|
|
|
|
|
@@ -229,12 +245,12 @@ class FindBoxService
|
|
|
$labelJ = join(', ', $label->id);
|
|
$labelJ = join(', ', $label->id);
|
|
|
$this->ServiceLogger->write("BlinkOff for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
$this->ServiceLogger->write("BlinkOff for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
- $jobManager->RemoveLabelsFromJobs($label->id);
|
|
|
|
|
|
|
+ $this->jobManager->RemoveLabelsFromJobs($label->id);
|
|
|
|
|
|
|
|
// Rimuove il JOB se esiste
|
|
// Rimuove il JOB se esiste
|
|
|
$asyncBlinkOFF = new AsyncJobClass($this->findBoxCore, $label->id);
|
|
$asyncBlinkOFF = new AsyncJobClass($this->findBoxCore, $label->id);
|
|
|
$asyncBlinkOFF->BlinkOFF();
|
|
$asyncBlinkOFF->BlinkOFF();
|
|
|
- $jobManager->add($asyncBlinkOFF);
|
|
|
|
|
|
|
+ $this->jobManager->add($asyncBlinkOFF);
|
|
|
|
|
|
|
|
unset($this->labelToBlink[$commandID]);
|
|
unset($this->labelToBlink[$commandID]);
|
|
|
|
|
|
|
@@ -244,11 +260,11 @@ class FindBoxService
|
|
|
$labelJ = join(', ', $label->id);
|
|
$labelJ = join(', ', $label->id);
|
|
|
$this->ServiceLogger->write("BlinkOn for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
$this->ServiceLogger->write("BlinkOn for label(s) {$labelJ} requested", 'd/m/Y H:i:s');
|
|
|
|
|
|
|
|
- $jobManager->RemoveLabelsFromJobs($label->id);
|
|
|
|
|
|
|
+ $this->jobManager->RemoveLabelsFromJobs($label->id);
|
|
|
|
|
|
|
|
$asyncBlink = new AsyncJobClass($this->findBoxCore, $label->id, $label->params);
|
|
$asyncBlink = new AsyncJobClass($this->findBoxCore, $label->id, $label->params);
|
|
|
$asyncBlink->BlinkON();
|
|
$asyncBlink->BlinkON();
|
|
|
- $jobManager->add($asyncBlink);
|
|
|
|
|
|
|
+ $this->jobManager->add($asyncBlink);
|
|
|
|
|
|
|
|
unset($this->labelToBlink[$commandID]);
|
|
unset($this->labelToBlink[$commandID]);
|
|
|
|
|
|
|
@@ -257,7 +273,7 @@ class FindBoxService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Async check on JOBS
|
|
// Async check on JOBS
|
|
|
- $jobManager->Run(function (AsyncJobClass $asyncBlink) {
|
|
|
|
|
|
|
+ $this->jobManager->Run(function (AsyncJobClass $asyncBlink) {
|
|
|
|
|
|
|
|
$err = $asyncBlink->GetCurrentValue(); // Fa scattare il generator e ricava il valore
|
|
$err = $asyncBlink->GetCurrentValue(); // Fa scattare il generator e ricava il valore
|
|
|
|
|
|
|
@@ -284,31 +300,45 @@ class FindBoxService
|
|
|
|
|
|
|
|
private function getCurrentQueue()
|
|
private function getCurrentQueue()
|
|
|
{
|
|
{
|
|
|
- if ($this->qs_Server->check()) {
|
|
|
|
|
-
|
|
|
|
|
- /** @var QueueCommand $qCommand */
|
|
|
|
|
- $qCommand = $this->qs_Server->getCommandObject();
|
|
|
|
|
- switch ($qCommand->operation) {
|
|
|
|
|
- case QueueCommand::$Q_SAVEPRODUCT:
|
|
|
|
|
- $this->saveProduct($qCommand);
|
|
|
|
|
- break;
|
|
|
|
|
- case QueueCommand::$Q_BLINK_ON:
|
|
|
|
|
- case QueueCommand::$Q_BLINK_OFF:
|
|
|
|
|
- // Split blink list by 9 items each array
|
|
|
|
|
- $labelsSplitted = array_chunk($qCommand->id, 9);
|
|
|
|
|
- foreach($labelsSplitted as $labels) {
|
|
|
|
|
- $cmd = clone $qCommand;
|
|
|
|
|
- $cmd->id = $labels;
|
|
|
|
|
- $this->labelToBlink[rand(0, 60000)] = $cmd;
|
|
|
|
|
- }
|
|
|
|
|
- break;
|
|
|
|
|
- case QueueCommand::$Q_DISPLAY:
|
|
|
|
|
- $this->ServiceLogger->write("Change display for label {$qCommand->id} requested", 'd/m/Y H:i:s');
|
|
|
|
|
- $esl = new SmartESL($this->findBoxCore, $qCommand->id);
|
|
|
|
|
- $esl->Display($qCommand->params['templateId'], $qCommand->params['barcode']);
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ /** @var QueueCommand $qCommand */
|
|
|
|
|
+ $this->qs_Server->ServerCheckClientCommands(
|
|
|
|
|
+ function ($clientCommands) {
|
|
|
|
|
+ switch ($clientCommands->operation) {
|
|
|
|
|
+
|
|
|
|
|
+ case QueueCommand::$Q_GETJOBS:
|
|
|
|
|
+ return ['jobCount' => $this->jobManager->count()];
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case QueueCommand::$Q_CLEARQUEUE:
|
|
|
|
|
+ $this->ServiceLogger->write("Clear jobs requested", 'd/m/Y H:i:s');
|
|
|
|
|
+ $this->jobManager->Reset();
|
|
|
|
|
+ return ['jobClear' => true];
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case QueueCommand::$Q_SAVEPRODUCT:
|
|
|
|
|
+ $this->saveProduct($clientCommands);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case QueueCommand::$Q_BLINK_ON:
|
|
|
|
|
+ case QueueCommand::$Q_BLINK_OFF:
|
|
|
|
|
+ // Split blink list by 9 items each array
|
|
|
|
|
+ $labelsSplitted = array_chunk($clientCommands->id, 9);
|
|
|
|
|
+ foreach($labelsSplitted as $labels) {
|
|
|
|
|
+ $cmd = clone $clientCommands;
|
|
|
|
|
+ $cmd->id = $labels;
|
|
|
|
|
+ $this->labelToBlink[rand(0, 60000)] = $cmd;
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case QueueCommand::$Q_DISPLAY:
|
|
|
|
|
+ $this->ServiceLogger->write("Change display for label {$clientCommands->id} requested", 'd/m/Y H:i:s');
|
|
|
|
|
+ $esl = new SmartESL($this->findBoxCore, $clientCommands->id);
|
|
|
|
|
+ $esl->Display($clientCommands->params['templateId'], $clientCommands->params['barcode']);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return NULL;
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|