Skip to content

Commit

Permalink
fix: predis leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
Grafikart committed Nov 1, 2024
1 parent 0082078 commit 267fca5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 0 additions & 4 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ services:
App\Infrastructure\Queue\FailedJobsService:
arguments: ['@messenger.transport.failed']

App\Infrastructure\Queue\ScheduledJobsService:
arguments:
$dsn: '%env(MESSENGER_TRANSPORT_DSN)%'

App\Infrastructure\Spam\SpamService:
arguments: [['App\Domain\Forum\Entity\Topic', 'App\Domain\Forum\Entity\Message']]

Expand Down
7 changes: 7 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ services:
- .:/var/www:delegated
links:
- dbtest
- redistest
networks:
- test
environment:
REDIS_HOST: redistest
DATABASE_URL: postgresql://test:test@dbtest:5432/test?serverVersion=12&charset=utf8
redistest:
restart: unless-stopped
image: redis:7-alpine
networks:
- test
dbtest:
image: postgres:12
environment:
Expand Down
15 changes: 3 additions & 12 deletions src/Infrastructure/Queue/ScheduledJobsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,22 @@

namespace App\Infrastructure\Queue;

use Predis\Client;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;

class ScheduledJobsService
{
public function __construct(
private readonly string $dsn,
private readonly \Redis $redis,
private readonly SerializerInterface $serializer,
) {
}

public function getConnection(): Client
{
return new Client($this->dsn);
}

/**
* @return ScheduledJob[]
*/
public function getJobs(): array
{
if (!str_starts_with($this->dsn, 'redis://')) {
return [];
}
$messages = $this->getConnection()->zrange('messages__queue', 0, 10);
$messages = $this->redis->zrange('messages__queue', 0, 10);
if (empty($messages)) {
return [];
}
Expand All @@ -39,6 +30,6 @@ public function getJobs(): array

public function deleteJob(int $jobId): void
{
$this->getConnection()->zremrangebyrank('messages__queue', $jobId, $jobId);
$this->redis->zremrangebyrank('messages__queue', $jobId, $jobId);
}
}

0 comments on commit 267fca5

Please sign in to comment.