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