File tree Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ use v5.36;
7
7
use MetaCPAN::Logger qw< :log :dlog > ;
8
8
use Search::Elasticsearch;
9
9
10
- use MetaCPAN::Ingest qw< config > ;
10
+ use MetaCPAN::Ingest qw< config handle_error > ;
11
11
12
12
sub new ( $class , %args ) {
13
13
my $node = $args {node };
@@ -142,4 +142,48 @@ sub clear_type ($self) {
142
142
$self -> delete_ids(@$ids );
143
143
}
144
144
145
+ sub await ( $self ) {
146
+ my $timeout = 15;
147
+ my $iready = 0;
148
+ my $cluster_info ;
149
+ my $es = $self -> {es };
150
+
151
+ if ( scalar ( keys %$cluster_info ) == 0 ) {
152
+ my $iseconds = 0;
153
+
154
+ log_info {" Awaiting Elasticsearch ..." };
155
+
156
+ do {
157
+ eval {
158
+ $iready = $es -> ping;
159
+
160
+ if ($iready ) {
161
+ log_info { sprintf (" Awaiting %d / %d : ready" , $iseconds , $timeout ) };
162
+ $cluster_info = \%{ $es -> info };
163
+ }
164
+ };
165
+
166
+ if ($@ ) {
167
+ if ( $iseconds < $timeout ) {
168
+ log_info { sprintf (" Awaiting %d / %d : unavailable - sleeping ..." , $iseconds , $timeout ) };
169
+ sleep (1);
170
+ $iseconds ++;
171
+ }
172
+ else {
173
+ log_info { sprintf (" Awaiting %d / %d : unavailable - timeout!" , $iseconds , $timeout ) };
174
+
175
+ # Set System Error: 112 - EHOSTDOWN - Host is down
176
+ handle_error( 112, $@ , 1 );
177
+ }
178
+ }
179
+ } while ( !$iready && $iseconds <= $timeout );
180
+ }
181
+ else {
182
+ # ElasticSearch Service is available
183
+ $iready = 1;
184
+ }
185
+
186
+ return $iready ;
187
+ }
188
+
145
189
1;
You can’t perform that action at this time.
0 commit comments