Skip to content

Commit 82f6560

Browse files
authored
Merge pull request #6 from php-enqueue/solution-based-on-pager-persister
Solution based on pager persister provider API.
2 parents 7c05c55 + 9013a16 commit 82f6560

11 files changed

+362
-290
lines changed

Async/ElasticaPopulateProcessor.php

-86
This file was deleted.

DependencyInjection/Compiler/AsyncProviderCompilerPass.php

-35
This file was deleted.

Elastica/AsyncDoctrineOrmProvider.php

-107
This file was deleted.

EnqueueElasticaBundle.php

-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22

33
namespace Enqueue\ElasticaBundle;
44

5-
use Enqueue\ElasticaBundle\DependencyInjection\Compiler\AsyncProviderCompilerPass;
6-
use Symfony\Component\DependencyInjection\ContainerBuilder;
75
use Symfony\Component\HttpKernel\Bundle\Bundle;
86

97
class EnqueueElasticaBundle extends Bundle
108
{
11-
/**
12-
* {@inheritdoc}
13-
*/
14-
public function build(ContainerBuilder $container)
15-
{
16-
$container->addCompilerPass(new AsyncProviderCompilerPass());
17-
}
189
}

Listener/PurgeFosElasticPopulateQueueListener.php

-41
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
namespace Enqueue\ElasticaBundle\Persister\Listener;
3+
4+
use FOS\ElasticaBundle\Persister\Event\PrePersistEvent;
5+
use Interop\Queue\PsrContext;
6+
use FOS\ElasticaBundle\Persister\Event\Events;
7+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8+
9+
class PurgePopulateQueueListener implements EventSubscriberInterface
10+
{
11+
/**
12+
* @var PsrContext
13+
*/
14+
private $context;
15+
16+
/**
17+
* @param PsrContext $context
18+
*/
19+
public function __construct(PsrContext $context)
20+
{
21+
$this->context = $context;
22+
}
23+
24+
public function purgePopulateQueue(PrePersistEvent $event)
25+
{
26+
$options = $event->getOptions();
27+
if (empty($options['purge_populate_queue'])) {
28+
return;
29+
}
30+
if (empty($options['populate_queue'])) {
31+
return;
32+
}
33+
34+
if (method_exists($this->context, 'purge')) {
35+
$queue = $this->context->createQueue($options['populate_queue']);
36+
37+
$this->context->purge($queue);
38+
}
39+
40+
if (method_exists($this->context, 'purgeQueue')) {
41+
$queue = $this->context->createQueue($options['populate_queue']);
42+
43+
$this->context->purgeQueue($queue);
44+
}
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public static function getSubscribedEvents()
51+
{
52+
return [
53+
Events::PRE_PERSIST => 'purgePopulateQueue',
54+
];
55+
}
56+
}

0 commit comments

Comments
 (0)