Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(indexer): allow clean exit by stopping worker #90

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/indexer/src/data-indexing/service/Indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Indexer {
public stopGracefully() {
this.logger.info({
at: "Indexer::stopGracefully",
message: `Requesting indexer ${this.dataHandler.getDataIdentifier()} to be stoped`,
message: `Requesting indexer ${this.dataHandler.getDataIdentifier()} to be stopped`,
});
this.stopRequested = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer/src/generics/BaseIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export abstract class BaseIndexer {
public stop(): void {
this.logger.info({
at: "BaseIndexer#stop",
message: `Requesting indexer ${this.name} to be stoped`,
message: `Requesting indexer ${this.name} to be stopped`,
});
this.stopRequested = true;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/indexer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ export async function Main(config: parseEnv.Config, logger: winston.Logger) {

const indexerQueuesService = new IndexerQueuesService(redis);
// Set up message workers
new IntegratorIdWorker(redis, postgres, logger, retryProvidersFactory);
const integratorIdWorker = new IntegratorIdWorker(
redis,
postgres,
logger,
retryProvidersFactory,
);

const spokePoolIndexers = spokePoolChainsEnabled.map((chainId) => {
const spokePoolIndexerDataHandler = new SpokePoolIndexerDataHandler(
Expand Down Expand Up @@ -156,11 +161,13 @@ export async function Main(config: parseEnv.Config, logger: winston.Logger) {
at: "Indexer#Main",
message: "Wait for shutdown, or press Ctrl+C again to forcefully exit.",
});
integratorIdWorker.close();
spokePoolIndexers.map((s) => s.stopGracefully());
hubPoolIndexer.stopGracefully();
bundleProcessor.stop();
bundleBuilderProcessor.stop();
} else {
integratorIdWorker.close();
logger.info({ at: "Indexer#Main", message: "Forcing exit..." });
redis?.quit();
postgres?.destroy();
Expand Down Expand Up @@ -195,7 +202,7 @@ export async function Main(config: parseEnv.Config, logger: winston.Logger) {
bundleBuilderResult.status === "fulfilled",
},
});

await integratorIdWorker.close();
redis?.quit();
postgres?.destroy();
logger.info({ at: "Indexer#Main", message: "Exiting indexer" });
Expand Down
4 changes: 3 additions & 1 deletion packages/indexer/src/messaging/IntegratorIdWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class IntegratorIdWorker {
{ connection: this.redis, concurrency: 10 },
);
}

private async run(relayHash: string) {
const repository = this.postgres.getRepository(entities.V3FundsDeposited);
const deposit = await repository.findOne({
Expand Down Expand Up @@ -80,4 +79,7 @@ export class IntegratorIdWorker {
}
return;
}
public async close() {
return this.worker.close();
}
}