|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bdf\QueueBundle\DependencyInjection\Failer; |
|
4
|
|
|
|
|
5
|
|
|
use Bdf\Dsn\DsnRequest; |
|
6
|
|
|
use Bdf\Queue\Console\Command\Failer\InitCommand; |
|
|
|
|
|
|
7
|
|
|
use Bdf\Queue\Failer\DbFailedJobRepository; |
|
|
|
|
|
|
8
|
|
|
use Bdf\Queue\Failer\DbFailedJobStorage; |
|
|
|
|
|
|
9
|
|
|
use Bdf\Queue\Failer\FailedJobRepositoryAdapter; |
|
10
|
|
|
use Bdf\Queue\Failer\FailedJobRepositoryInterface; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Configurator for failer repository using prime. |
|
16
|
|
|
* |
|
17
|
|
|
* The package "b2pweb/bdf-queue-prime-adapter" must be installed and |
|
18
|
|
|
* "b2pweb/bdf-prime-bundle" configure to enable this failer repository |
|
19
|
|
|
* |
|
20
|
|
|
* DSN format: "prime://[connection]/[table]?maxRows=[cursorSize]" |
|
21
|
|
|
* with: |
|
22
|
|
|
* - [connection] as the prime connection to use for store failed jobs |
|
23
|
|
|
* - [table] as the table name |
|
24
|
|
|
* - [cursorSize] (optional): number of loaded jobs each times by the cursor with calling |
|
25
|
|
|
* `FailedJobRepositoryInterface::all()` or `search()`. Default value is 50 |
|
26
|
|
|
*/ |
|
27
|
|
|
final class PrimeFailerDriverConfigurator implements FailerDriverConfiguratorInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
3 |
|
public function scheme(): string |
|
33
|
|
|
{ |
|
34
|
3 |
|
return 'prime'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
3 |
|
public function available(ContainerBuilder $container): bool |
|
41
|
|
|
{ |
|
42
|
3 |
|
if (!$container->has('prime')) { |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
3 |
|
return class_exists(DbFailedJobRepository::class) || class_exists(DbFailedJobStorage::class); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function configure(DsnRequest $dsn, ContainerBuilder $container): string |
|
53
|
|
|
{ |
|
54
|
3 |
|
if (!$host = $dsn->getHost()) { |
|
55
|
1 |
|
throw new \InvalidArgumentException('The connection name is required on prime failer DSN'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
if (!$path = trim($dsn->getPath(), '/')) { |
|
|
|
|
|
|
59
|
1 |
|
throw new \InvalidArgumentException('The table name is required on prime failer DSN'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
$className = class_exists(DbFailedJobRepository::class) |
|
63
|
1 |
|
? DbFailedJobRepository::class |
|
64
|
|
|
: DbFailedJobStorage::class |
|
65
|
1 |
|
; |
|
66
|
|
|
|
|
67
|
1 |
|
$container->register($className, $className) |
|
68
|
1 |
|
->setFactory([$className, 'make']) |
|
69
|
1 |
|
->setArguments([ |
|
70
|
1 |
|
new Reference('prime'), |
|
71
|
1 |
|
[ |
|
72
|
1 |
|
'connection' => $host, |
|
73
|
1 |
|
'table' => $path, |
|
74
|
1 |
|
], |
|
75
|
1 |
|
$dsn->query('maxRows', 50), |
|
76
|
1 |
|
]) |
|
77
|
1 |
|
; |
|
78
|
|
|
|
|
79
|
|
|
// Register init command |
|
80
|
1 |
|
$container->register(InitCommand::class, InitCommand::class) |
|
81
|
1 |
|
->addArgument(new Reference($className)) |
|
82
|
1 |
|
->addTag('console.command') |
|
83
|
1 |
|
; |
|
84
|
|
|
|
|
85
|
1 |
|
if (is_subclass_of($className, FailedJobRepositoryInterface::class)) { |
|
86
|
1 |
|
return $className; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// Compatibility with legacy prime driver : adapt to repository interface |
|
90
|
|
|
$container->register('bdf_queue.failer.prime_repository', FailedJobRepositoryAdapter::class) |
|
91
|
|
|
->setFactory([FailedJobRepositoryAdapter::class, 'adapt']) |
|
92
|
|
|
->setArguments([new Reference($className)]) |
|
93
|
|
|
; |
|
94
|
|
|
|
|
95
|
|
|
return 'bdf_queue.failer.prime_repository'; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths