Skip to content

Commit

Permalink
fix: enable dynamic setting of es scroll timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
JanssenBrm committed Dec 2, 2024
1 parent 264b4a2 commit c081558
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/config/schema/config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,12 @@ export const schema: convict.Schema<AppConfig> = {
env: 'DB_JOBS_IDX',
arg: 'db_jobs_idx',
},
jobsScrollTimout: {
doc: 'Timeout of the scroll to use in elasticsearch',
format: '*',
default: '5s',
env: 'DB_JOBS_SCOLL_TIMEOUT',
arg: 'db_jobs_scroll_timeout',
},
},
};
12 changes: 10 additions & 2 deletions src/jobs/services/database/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import { ApiResponse } from '@elastic/elasticsearch';
@Injectable()
export class DatabaseService {
private JOBS_INDEX = '';
private JOBS_SCROLL_TIMEOUT = '5s';

constructor(
private configService: ConfigService,
private elasticSearch: ElasticsearchService,
private logger: Logger,
) {
this.JOBS_INDEX = this.configService.get('database.jobsIdx');
this.JOBS_SCROLL_TIMEOUT = this.configService.get(
'database.jobsScrollTimout',
);

this.logger.debug(
`Starting up databse service for jobs at index ${this.JOBS_INDEX} and scroll timeout of ${this.JOBS_SCROLL_TIMEOUT}`,
);
}

/**
Expand Down Expand Up @@ -115,7 +123,7 @@ export class DatabaseService {
// Perform initial search
const results = await this.elasticSearch.search({
index: this.JOBS_INDEX,
scroll: '5s',
scroll: this.JOBS_SCROLL_TIMEOUT,
body: query,
size: limit || 1000,
});
Expand All @@ -134,7 +142,7 @@ export class DatabaseService {
queue.push(
await this.elasticSearch.scroll({
scroll_id: body._scroll_id,
scroll: '5s',
scroll: this.JOBS_SCROLL_TIMEOUT,
}),
);
}
Expand Down

0 comments on commit c081558

Please sign in to comment.