19
19
*/
20
20
final class MeiliSearchImportCommand extends IndexCommand
21
21
{
22
+ private const DEFAULT_RESPONSE_TIMEOUT = 5000 ;
23
+
22
24
protected static $ defaultName = 'meili:import ' ;
23
25
protected Client $ searchClient ;
24
26
protected ManagerRegistry $ managerRegistry ;
@@ -41,7 +43,15 @@ protected function configure(): void
41
43
InputOption::VALUE_NONE ,
42
44
'Update settings related to indices to the search engine '
43
45
)
44
- ->addOption ('batch-size ' , null , InputOption::VALUE_REQUIRED );
46
+ ->addOption ('batch-size ' , null , InputOption::VALUE_REQUIRED )
47
+ ->addOption (
48
+ 'response-timeout ' ,
49
+ 't ' ,
50
+ InputOption::VALUE_REQUIRED ,
51
+ 'Timeout (in ms) to get response from the search engine ' ,
52
+ self ::DEFAULT_RESPONSE_TIMEOUT
53
+ )
54
+ ;
45
55
}
46
56
47
57
protected function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -67,6 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
67
77
$ entitiesToIndex = array_unique ($ indexes ->toArray (), SORT_REGULAR );
68
78
$ batchSize = $ input ->getOption ('batch-size ' );
69
79
$ batchSize = ctype_digit ($ batchSize ) ? (int ) $ batchSize : $ config ->get ('batchSize ' );
80
+ $ responseTimeout = ((int ) $ input ->getOption ('response-timeout ' )) ?: self ::DEFAULT_RESPONSE_TIMEOUT ;
70
81
71
82
/** @var array $index */
72
83
foreach ($ entitiesToIndex as $ index ) {
@@ -89,7 +100,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
89
100
$ batchSize * $ page
90
101
);
91
102
92
- $ responses = $ this ->formatIndexingResponse ($ this ->searchService ->index ($ manager , $ entities ));
103
+ $ responses = $ this ->formatIndexingResponse ($ this ->searchService ->index ($ manager , $ entities ), $ responseTimeout );
93
104
foreach ($ responses as $ indexName => $ numberOfRecords ) {
94
105
$ output ->writeln (
95
106
sprintf (
@@ -116,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116
127
$ update = $ indexInstance ->{$ method }($ value );
117
128
118
129
// Get Update status from updateID
119
- $ indexInstance ->waitForPendingUpdate ($ update ['updateId ' ]);
130
+ $ indexInstance ->waitForPendingUpdate ($ update ['updateId ' ], $ responseTimeout );
120
131
$ updateStatus = $ indexInstance ->getUpdateStatus ($ update ['updateId ' ]);
121
132
122
133
if ('failed ' === $ updateStatus ['status ' ]) {
@@ -141,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
141
152
/*
142
153
* @throws TimeOutException
143
154
*/
144
- private function formatIndexingResponse (array $ batch ): array
155
+ private function formatIndexingResponse (array $ batch, int $ responseTimeout ): array
145
156
{
146
157
$ formattedResponse = [];
147
158
@@ -154,7 +165,7 @@ private function formatIndexingResponse(array $batch): array
154
165
$ indexInstance = $ this ->searchClient ->index ($ indexName );
155
166
156
167
// Get Update status from updateID
157
- $ indexInstance ->waitForPendingUpdate ($ apiResponse ['updateId ' ]);
168
+ $ indexInstance ->waitForPendingUpdate ($ apiResponse ['updateId ' ], $ responseTimeout );
158
169
$ updateStatus = $ indexInstance ->getUpdateStatus ($ apiResponse ['updateId ' ]);
159
170
160
171
if ('failed ' === $ updateStatus ['status ' ]) {
0 commit comments