Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-rosianu committed Sep 24, 2024
1 parent 4687b75 commit 433bacd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ module.exports = {
"@typescript-eslint/ban-types": ["off"]
},
ignorePatterns: ['.eslintrc.js'],
};
};
46 changes: 25 additions & 21 deletions src/event.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,36 @@ export class EventProcessor {
}

async callElasticsearchEvents(lastProcessedTimestamp: number): Promise<void> {
const url = `${this.options.elasticUrl}/events/_search?scroll=${this.options.scrollTimeout}`;
const elasticQuery = this.generateElasticsearchQuery(lastProcessedTimestamp);
const result = await axios.post(url, elasticQuery);
try {
const url = `${this.options.elasticUrl}/events/_search?scroll=${this.options.scrollTimeout}`;
const elasticQuery = this.generateElasticsearchQuery(lastProcessedTimestamp);
const result = await axios.post(url, elasticQuery);

if (!result.data || !result.data.hits || !result.data.hits || !result.data.hits.hits) {
return;
}
if (!result.data || !result.data.hits || !result.data.hits || !result.data.hits.hits) {
return;
}

const elasticEvents = result.data.hits.hits;
const events = elasticEvents.map((e: { _source: any; }) => e._source);
await this.handleElasticEvents(events);
const elasticEvents = result.data.hits.hits;
const events = elasticEvents.map((e: { _source: any; }) => e._source);
await this.handleElasticEvents(events);

const scrollId = result.data._scroll_id;
while (true) {
const scrollResult = await axios.post(`${this.options.elasticUrl}/_search/scroll`,
{
scroll_id: scrollId,
});
const scrollId = result.data._scroll_id;
while (true) {
const scrollResult = await axios.post(`${this.options.elasticUrl}/_search/scroll`,
{
scroll_id: scrollId,
});

const scrollDocuments = scrollResult.data.hits.hits;
if (scrollDocuments.length === 0) {
break;
}
const scrollDocuments = scrollResult?.data?.hits?.hits ?? [];
if (scrollDocuments.length === 0) {
break;
}

const scrollEvents = scrollDocuments.map((e: { _source: any; }) => e._source);
await this.handleElasticEvents(scrollEvents);
const scrollEvents = scrollDocuments.map((e: { _source: any; }) => e._source);
await this.handleElasticEvents(scrollEvents);
}
} catch (error) {
throw new Error(`Error while fetching events from Elasticsearch: ${error}`);
}
}

Expand Down

0 comments on commit 433bacd

Please sign in to comment.