Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
adapter:
[
AMQP,
Pool,
SwooleRedisCluster,
Swoole,
Workerman,
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer as composer
FROM composer AS composer

WORKDIR /usr/local/src/

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"utopia-php/cli": "0.15.*",
"utopia-php/framework": "0.33.*",
"utopia-php/telemetry": "0.1.*",
"utopia-php/pools": "0.8.*",
"utopia-php/fetch": "0.4.*"
},
"require-dev": {
Expand Down
110 changes: 81 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions src/Queue/Broker/Pool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Utopia\Queue\Broker;

use Utopia\Queue\Consumer;
use Utopia\Queue\Publisher;
use Utopia\Queue\Queue;
use Utopia\Pools\Pool as UtopiaPool;

readonly class Pool implements Publisher, Consumer
{
public function __construct(
private ?UtopiaPool $publisher = null,
private ?UtopiaPool $consumer = null,
) {
}

public function enqueue(Queue $queue, array $payload): bool
{
return $this->delegatePublish(__FUNCTION__, \func_get_args());
}

public function retry(Queue $queue, ?int $limit = null): void
{
$this->delegatePublish(__FUNCTION__, \func_get_args());
}

public function getQueueSize(Queue $queue, bool $failedJobs = false): int
{
return $this->delegatePublish(__FUNCTION__, \func_get_args());
}

public function consume(Queue $queue, callable $messageCallback, callable $successCallback, callable $errorCallback): void
{
$this->delegateConsumer(__FUNCTION__, \func_get_args());
}

public function close(): void
{
$this->delegateConsumer(__FUNCTION__, \func_get_args());
}

protected function delegatePublish(string $method, array $args): mixed
{
return $this->publisher?->use(function (Publisher $adapter) use ($method, $args) {
return $adapter->$method(...$args);
});
}

protected function delegateConsumer(string $method, array $args): mixed
{
return $this->consumer?->use(function (Consumer $adapter) use ($method, $args) {
return $adapter->$method(...$args);
});
}
}
3 changes: 1 addition & 2 deletions tests/Queue/E2E/Adapter/AMQPTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

namespace Queue\E2E\Adapter;
namespace Tests\E2E\Adapter;

use Tests\E2E\Adapter\Base;
use Utopia\Queue\Broker\AMQP;
use Utopia\Queue\Publisher;
use Utopia\Queue\Queue;
Expand Down
27 changes: 27 additions & 0 deletions tests/Queue/E2E/Adapter/PoolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Tests\E2E\Adapter;

use Utopia\Pools\Pool as UtopiaPool;
use Utopia\Queue\Broker\Pool;
use Utopia\Queue\Broker\Redis as RedisBroker;
use Utopia\Queue\Connection\Redis;
use Utopia\Queue\Publisher;
use Utopia\Queue\Queue;

class PoolTest extends Base
{
protected function getPublisher(): Publisher
{
$pool = new UtopiaPool('redis', 1, function () {
return new RedisBroker(new Redis('redis', 6379));
});

return new Pool($pool, $pool);
}

protected function getQueue(): Queue
{
return new Queue('pool');
}
}
3 changes: 1 addition & 2 deletions tests/Queue/E2E/Adapter/SwooleRedisClusterTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

namespace Queue\E2E\Adapter;
namespace Tests\E2E\Adapter;

use Tests\E2E\Adapter\Base;
use Utopia\Queue\Broker\Redis;
use Utopia\Queue\Connection\RedisCluster;
use Utopia\Queue\Publisher;
Expand Down