Skip to content

Commit

Permalink
[Code] Enforce progress update at the end of the index job (#43381) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mw-ding committed Aug 17, 2019
1 parent e18eca6 commit 4d89981
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export abstract class AbstractIndexer implements Indexer {
percentage: Math.floor((100 * (successCount + failCount)) / totalCount),
checkpoint: req,
};
if (moment().diff(prevTimestamp) > this.INDEXER_PROGRESS_UPDATE_INTERVAL_MS) {
if (
moment().diff(prevTimestamp) > this.INDEXER_PROGRESS_UPDATE_INTERVAL_MS ||
// Ensure that the progress reporter always executed at the end of the job.
successCount + failCount === totalCount
) {
progressReporter(progress);
prevTimestamp = moment();
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/code/server/queue/clone_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class CloneWorker extends AbstractGitWorker {
const repo = RepositoryUtils.buildRepository(url);

// Try to cancel any existing clone job for this repository.
this.cancellationService.cancelCloneJob(repo.uri, CancellationReason.NEW_JOB_OVERRIDEN);
await this.cancellationService.cancelCloneJob(repo.uri, CancellationReason.NEW_JOB_OVERRIDEN);

let cancelled = false;
let cancelledReason;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/code/server/queue/index_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class IndexWorker extends AbstractWorker {

// Binding the index cancellation logic
let cancelled = false;
this.cancellationService.cancelIndexJob(uri, CancellationReason.NEW_JOB_OVERRIDEN);
await this.cancellationService.cancelIndexJob(uri, CancellationReason.NEW_JOB_OVERRIDEN);
const indexPromises: Array<Promise<IndexStats>> = this.indexerFactories.map(
async (indexerFactory: IndexerFactory, index: number) => {
const indexer = await indexerFactory.create(uri, revision, enforceReindex);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/code/server/queue/update_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class UpdateWorker extends AbstractGitWorker {
);

// Try to cancel any existing update job for this repository.
this.cancellationService.cancelUpdateJob(repo.uri, CancellationReason.NEW_JOB_OVERRIDEN);
await this.cancellationService.cancelUpdateJob(repo.uri, CancellationReason.NEW_JOB_OVERRIDEN);

let cancelled = false;
let cancelledReason;
Expand Down

0 comments on commit 4d89981

Please sign in to comment.