Skip to content

Commit c68968a

Browse files
author
dmitriy
committed
fixed issue with elastic
1 parent 4475ab6 commit c68968a

File tree

9 files changed

+30
-4
lines changed

9 files changed

+30
-4
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ jobs:
1010
- checkout
1111

1212
- run:
13-
name: Start container and verify it's working
13+
name: Prepare and start containers and verify it's working
1414
command: |
15+
chmod 777 var/elasticsearch-data
1516
make start-test
1617
1718
- run:

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020

2121
steps:
2222
- uses: actions/checkout@v1
23+
- name: Set Elastic data folder rights
24+
run: chmod 777 var/elasticsearch-data
2325
- name: Build the docker images
2426
run: make build-test
2527
- name: Start the docker images

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ reports/*
99
/config/secrets/prod/prod.decrypt.private.php
1010
/public/bundles/
1111
/var/*
12-
!/var/elasticsearch-data/nodes/0/.gitkeep
12+
!/var/elasticsearch-data/.gitkeep
1313
/vendor/
1414
/tools/**/vendor
1515
###< symfony/framework-bundle ###

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ stages:
2323
build:
2424
stage: build
2525
script:
26+
- chmod 777 var/elasticsearch-data
2627
- make build-test
2728
- make start-test
2829
- docker ps -a

bitbucket-pipelines.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pipelines:
99
script:
1010
- chmod +x .bitbucket/dependencies.sh
1111
- .bitbucket/dependencies.sh
12+
- chmod 777 var/elasticsearch-data
1213
- make build-test
1314
- make start-test
1415
- docker ps -a

src/Command/Utils/WaitElasticCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6363
} catch (Exception $e) {
6464
$output->writeln('<comment>Trying to connect to elastic seconds:' . $i . '</comment>');
6565
sleep(self::WAIT_SLEEP_TIME);
66+
$this->elasticsearchService->instantiate();
6667

6768
continue;
6869
}

src/Service/ElasticsearchService.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class ElasticsearchService implements ElasticsearchServiceInterface
2121
public const INDEX_PREFIX = 'index';
2222
public const INDEX_DATE_FORMAT = 'Y_m_d';
2323
public const TEMPLATE_NAME = 'template_1';
24+
25+
private string $host;
26+
private string $username;
27+
private string $password;
2428
private Client $client;
2529

2630
/**
@@ -32,8 +36,19 @@ class ElasticsearchService implements ElasticsearchServiceInterface
3236
*/
3337
public function __construct(string $host, string $username, string $password)
3438
{
35-
$this->client = ClientBuilder::create()->setHosts([$host])
36-
->setBasicAuthentication($username, $password)
39+
$this->host = $host;
40+
$this->username = $username;
41+
$this->password = $password;
42+
$this->instantiate();
43+
}
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
public function instantiate(): void
49+
{
50+
$this->client = ClientBuilder::create()->setHosts([$this->host])
51+
->setBasicAuthentication($this->username, $this->password)
3752
->build();
3853
}
3954

src/Service/Interfaces/ElasticsearchServiceInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
interface ElasticsearchServiceInterface
1515
{
16+
/**
17+
* Instantiate client instance
18+
*/
19+
public function instantiate(): void;
20+
1621
/**
1722
* Index a document
1823
*

0 commit comments

Comments
 (0)