Beanstalkd -> Pheanstalk
This commit is contained in:
@ -8,11 +8,13 @@
|
||||
"ext-gd": "*",
|
||||
"ext-openssl": "*",
|
||||
"ext-pdo": "*",
|
||||
"ext-sockets": "*",
|
||||
"berrnd/slim-blade-view": "^1",
|
||||
"guzzlehttp/guzzle": "^7",
|
||||
"monolog/monolog": "^3",
|
||||
"nyholm/psr7": "^1",
|
||||
"nyholm/psr7-server": "^1",
|
||||
"pda/pheanstalk": "^7.0",
|
||||
"php-di/php-di": "^7",
|
||||
"php-di/slim-bridge": "^3",
|
||||
"phpoffice/phpspreadsheet": "^3",
|
||||
@ -20,8 +22,7 @@
|
||||
"robmorgan/phinx": "^0.16",
|
||||
"slim/slim": "^4",
|
||||
"symfony/string": "^7.2",
|
||||
"tedivm/jshrink": "^1.7",
|
||||
"xobotyi/beansclient": "^1.0"
|
||||
"tedivm/jshrink": "^1.7"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1",
|
||||
|
@ -162,15 +162,15 @@ return [
|
||||
->register('subscription', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Subscription::class))
|
||||
->register('invoice', $container->get(Incoviba\Service\Venta\MediosPago\Toku\Invoice::class));
|
||||
},
|
||||
xobotyi\beansclient\Interfaces\ConnectionInterface::class => function(ContainerInterface $container) {
|
||||
return new xobotyi\beansclient\Connection(
|
||||
Pheanstalk\Pheanstalk::class => function(ContainerInterface $container) {
|
||||
return Pheanstalk\Pheanstalk::create(
|
||||
$container->get('BEANSTALKD_HOST'),
|
||||
$container->has('BEANSTALKD_PORT') ? $container->get('BEANSTALKD_PORT') : 11300
|
||||
);
|
||||
},
|
||||
Incoviba\Service\MQTT::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\MQTT()
|
||||
->register('beanstalkd', $container->get(Incoviba\Service\MQTT\Beanstalkd::class));
|
||||
->register('default', $container->get(Incoviba\Service\MQTT\Pheanstalk::class));
|
||||
},
|
||||
Incoviba\Service\Queue::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Service\Queue(
|
||||
|
59
app/src/Service/MQTT/Pheanstalk.php
Normal file
59
app/src/Service/MQTT/Pheanstalk.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace Incoviba\Service\MQTT;
|
||||
|
||||
use Incoviba\Common\Ideal\Service;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Pheanstalk as PBA;
|
||||
|
||||
class Pheanstalk extends Service implements MQTTInterface
|
||||
{
|
||||
const string DEFAULT_TUBE = 'default';
|
||||
const int DEFAULT_TTR = 60;
|
||||
const int DEFAULT_PRIORITY = 1_024;
|
||||
|
||||
public function __construct(LoggerInterface $logger, protected PBA\Pheanstalk $client, string $tubeName = self::DEFAULT_TUBE)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
$this->tube = new PBA\Values\TubeName($tubeName);
|
||||
}
|
||||
|
||||
protected PBA\Values\TubeName $tube;
|
||||
|
||||
public function set(string $value, int $delay = 0): self
|
||||
{
|
||||
$this->client->useTube($this->tube);
|
||||
$this->client->put($value, self::DEFAULT_PRIORITY, $delay, self::DEFAULT_TTR);
|
||||
return $this;
|
||||
}
|
||||
public function exists(): bool
|
||||
{
|
||||
$stats = $this->client->statsTube($this->tube);
|
||||
return $stats->currentJobsReady > 0;
|
||||
}
|
||||
protected int $currentJobId;
|
||||
public function get(): string
|
||||
{
|
||||
$this->client->useTube($this->tube);
|
||||
$job = $this->client->reserve();
|
||||
$this->currentJobId = $job->getId();
|
||||
return $job->getData();
|
||||
}
|
||||
public function update(string $newPayload, ?int $jobId = null): self
|
||||
{
|
||||
if ($jobId === null) {
|
||||
$jobId = $this->currentJobId;
|
||||
}
|
||||
$this->remove($jobId);
|
||||
$this->set($newPayload);
|
||||
return $this;
|
||||
}
|
||||
public function remove(?int $jobId = null): self
|
||||
{
|
||||
if ($jobId === null) {
|
||||
$jobId = $this->currentJobId;
|
||||
}
|
||||
$this->client->useTube($this->tube);
|
||||
$this->client->delete(new PBA\Values\JobId($jobId));
|
||||
return $this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user