Skip to content

Commit

Permalink
Comment cron validators performance (#389)
Browse files Browse the repository at this point in the history
* comment cron validators performance

* fix build
  • Loading branch information
pablomendezroyo authored Oct 7, 2024
1 parent 3ae2652 commit c17d78d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
5 changes: 4 additions & 1 deletion packages/brain/src/calls/fetchValidatorsPerformanceData.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { fetchAndProcessValidatorsData } from "../modules/validatorsDataIngest/index.js";
import { minGenesisTime, postgresClient, secondsPerSlot } from "../index.js";
import { minGenesisTime, secondsPerSlot } from "../index.js";
import type {
ValidatorsDataProcessed,
Granularity,
NumberOfDaysToQuery
} from "../modules/validatorsDataIngest/types.js";
import { PostgresClient } from "../modules/apiClients/index.js";

export async function fetchValidatorsPerformanceData({
postgresClient,
validatorIndexes,
numberOfDaysToQuery,
granularity
}: {
postgresClient: PostgresClient;
validatorIndexes: string[];
numberOfDaysToQuery?: NumberOfDaysToQuery;
granularity?: Granularity;
Expand Down
42 changes: 21 additions & 21 deletions packages/brain/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import { params } from "./params.js";
import {
CronJob,
reloadValidators,
trackValidatorsPerformanceCron,
// trackValidatorsPerformanceCron,
sendProofsOfValidation
} from "./modules/cron/index.js";
import { PostgresClient } from "./modules/apiClients/index.js";
// import { PostgresClient } from "./modules/apiClients/index.js";
import { brainConfig } from "./modules/config/index.js";

logger.info(`Starting brain...`);
Expand Down Expand Up @@ -84,8 +84,8 @@ export const brainDb = new BrainDataBase(
);

// Create postgres client
export const postgresClient = new PostgresClient(postgresUrl);
await postgresClient.initialize().catch((err) => logger.error(`Error initializing table in postgres db`, err)); // TODO: handle error. Consider attempting to initialize on every cron iteration
// export const postgresClient = new PostgresClient(postgresUrl);
// await postgresClient.initialize().catch((err) => logger.error(`Error initializing table in postgres db`, err)); // TODO: handle error. Consider attempting to initialize on every cron iteration

// Start server APIs
const uiServer = startUiServer(path.resolve(__dirname, params.uiBuildDirName), network);
Expand All @@ -105,30 +105,30 @@ const proofOfValidationCron = new CronJob(shareCronInterval, () =>
proofOfValidationCron.start();

// execute the performance cron task every 1/4 of an epoch
export const trackValidatorsPerformanceCronTask = new CronJob(
((slotsPerEpoch * secondsPerSlot) / 4) * 1000,
async () => {
await trackValidatorsPerformanceCron({
brainDb,
postgresClient,
beaconchainApi,
executionClient,
consensusClient,
dappmanagerApi,
sendNotification: true
});
}
);
trackValidatorsPerformanceCronTask.start();
// export const trackValidatorsPerformanceCronTask = new CronJob(
// ((slotsPerEpoch * secondsPerSlot) / 4) * 1000,
// async () => {
// await trackValidatorsPerformanceCron({
// brainDb,
// postgresClient,
// beaconchainApi,
// executionClient,
// consensusClient,
// dappmanagerApi,
// sendNotification: true
// });
// }
// );
// trackValidatorsPerformanceCronTask.start();

// Graceful shutdown
function handle(signal: string): void {
logger.info(`${signal} received. Shutting down...`);
reloadValidatorsCron.stop();
proofOfValidationCron.stop();
trackValidatorsPerformanceCronTask.stop();
// trackValidatorsPerformanceCronTask.stop();
brainDb.close();
postgresClient.close().catch((err) => logger.error(`Error closing postgres client`, err)); // postgresClient db connection is the only external resource that needs to be closed
// postgresClient.close().catch((err) => logger.error(`Error closing postgres client`, err)); // postgresClient db connection is the only external resource that needs to be closed
uiServer.close();
launchpadServer.close();
logger.debug(`Stopped all cron jobs and closed all connections.`);
Expand Down

0 comments on commit c17d78d

Please sign in to comment.