Skip to content

Admin api #2415

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

Merged
merged 16 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/node-core/src/configure/ProjectUpgrade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class ProjectUpgradeService<P extends ISubqueryProject = ISubqueryProject
await this.migrate(project, newProject, undefined);
}
} catch (e: any) {
exitWithError(`Failed to complete upgrading project, ${e}`, logger, 1);
exitWithError(new Error(`Failed to complete upgrading project`, {cause: e}), logger, 1);
}

logger.info(`Project upgraded to ${newProject.id} at height ${height}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/db/db.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async function establishConnectionSequelize(option: SequelizeOption, numRetries:
await delay(3);
return establishConnectionSequelize(option, numRetries - 1);
} else {
exitWithError(`Unable to connect to the database,${error}`, logger);
exitWithError(new Error(`Unable to connect to the database`, {cause: error}), logger);
}
}
return sequelize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
return;
} catch (e: any) {
this.eventEmitter.emit(IndexerEvent.RewindFailure, {success: false, message: e.message});
monitorWrite(`***** Rewind failed: ${e.message}`);
throw e;
}
} else {
Expand All @@ -217,7 +218,7 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
if (this.nodeConfig.storeCacheAsync) {
// Flush all completed block data and don't wait
await this.storeCacheService.flushAndWaitForCapacity(false)?.catch((e) => {
exitWithError(`Flushing cache failed,${e}`, logger);
exitWithError(new Error(`Flushing cache failed`, {cause: e}), logger);
});
} else {
// Flush all data from cache and wait
Expand All @@ -226,9 +227,8 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB

if (!this.projectService.hasDataSourcesAfterHeight(height)) {
const msg = `All data sources have been processed up to block number ${height}. Exiting gracefully...`;
logger.info(msg);
await this.storeCacheService.flushCache(false);
exitWithError(msg, undefined, 0);
exitWithError(msg, logger, 0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export abstract class BlockDispatcher<B, DS>
// Do nothing, fetching the block was flushed, this could be caused by forked blocks or dynamic datasources
return;
}
exitWithError(`Failed to enqueue fetched block to process,${e}`, logger);
exitWithError(new Error(`Failed to enqueue fetched block to process`, {cause: e}), logger);
});

this.eventEmitter.emit(IndexerEvent.BlockQueueSize, {
Expand All @@ -206,7 +206,7 @@ export abstract class BlockDispatcher<B, DS>
}
} catch (e: any) {
if (!this.isShutdown) {
exitWithError(`Failed to process blocks from queue,${e}`, logger);
exitWithError(new Error(`Failed to process blocks from queue`, {cause: e}), logger);
}
} finally {
this.fetching = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/indexer/dynamic-ds.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export abstract class DynamicDsService<DS, P extends ISubqueryProject = ISubquer

return ds;
} catch (e: any) {
exitWithError(`Failed to create dynamic ds, ${e}`, logger);
exitWithError(new Error(`Failed to create dynamic ds`, {cause: e}), logger);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/indexer/poi/poiSync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class PoiSyncService implements OnApplicationShutdown {
this.isSyncing = false;
} catch (e) {
this.isSyncing = false;
exitWithError(`Failed to sync poi: ${e}`, logger);
exitWithError(new Error(`Failed to sync poi`, {cause: e}), logger);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/node-core/src/indexer/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class StoreService {
try {
await this.syncSchema(schema);
} catch (e: any) {
exitWithError(`Having a problem when syncing schema, ${e}`, logger);
exitWithError(new Error(`Having a problem when syncing schema`, {cause: e}), logger);
}
await this.updateModels(schema, modelsRelations);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ export class StoreService {
try {
this._modelIndexedFields = await this.getAllIndexFields(schema);
} catch (e: any) {
exitWithError(`Having a problem when get indexed fields, ${e}`, logger);
exitWithError(new Error(`Having a problem when get indexed fields`, {cause: e}), logger);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CsvStoreService implements Exporter {
this.writeStream = fs.createWriteStream(this.getCsvFilePath(), {flags: 'a'});

this.stringifyStream = stringify({header: !this.fileExist}).on('error', (err) => {
exitWithError(`Failed to write to CSV,${err}`, logger);
exitWithError(new Error(`Failed to write to CSV`, err), logger);
});
this.stringifyStream.pipe(this.writeStream);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/subcommands/foreceClean.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export async function forceClean(forceCleanModule: any): Promise<void> {
const forceCleanService = app.get(ForceCleanService);
await forceCleanService.forceClean();
} catch (e: any) {
exitWithError(`Force-clean failed to execute,${e}`, logger);
exitWithError(new Error(`Force-clean failed to execute`, {cause: e}), logger);
}

process.exit(0);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-core/src/subcommands/reindex.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function reindexInit(reindexModule: any, targetHeight: number): Pro
}
await reindexService.reindex(actualReindexHeight);
} catch (e: any) {
exitWithError(`Reindex failed to execute,${e}`, logger);
exitWithError(new Error(`Reindex failed to execute`, {cause: e}), logger);
}
process.exit(0);
}
2 changes: 1 addition & 1 deletion packages/node-core/src/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function getExistingProjectSchema(
});
schemas = result.map((x: any) => x.schema_name);
} catch (err) {
exitWithError(`Unable to fetch all schemas: ${err}`, logger);
exitWithError(new Error(`Unable to fetch all schemas`, {cause: err}), logger);
}
if (!schemas.includes(schema)) {
return undefined;
Expand Down
4 changes: 3 additions & 1 deletion packages/node-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"noImplicitAny": true,
"esModuleInterop": true,
"importHelpers": true,
"strict": true
"strict": true,
"target": "ES2022",
"lib": ["ES2022"]
},
"references": [{"path": "../common"}, {"path": "../utils"}, {"path": "../testing"}],
"include": ["src/**/*"]
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/indexer/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class ApiService
network.endpoint.push(this.nodeConfig.primaryNetworkEndpoint);
}
} catch (e) {
exitWithError(e, logger);
exitWithError(new Error(`Failed to init api`, { cause: e }), logger);
}

if (chainTypes) {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ export async function bootstrap(): Promise<void> {

logger.info(`Node started on port: ${port}`);
} catch (e) {
exitWithError(`Node failed to start,${e}`, logger);
exitWithError(new Error(`Node failed to start`, { cause: e }), logger);
}
}
2 changes: 1 addition & 1 deletion packages/node/src/subcommands/testing.init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function testingInit(): Promise<void> {
const testingService = new TestingService(nodeConfig, project);
await testingService.run();
} catch (e) {
exitWithError(`Testing failed,${e}`, logger);
exitWithError(new Error('Testing failed', { cause: e }), logger);
}
process.exit(0);
}
3 changes: 2 additions & 1 deletion packages/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"target": "es2017",
"target": "ES2022",
"lib": ["ES2022"],
"sourceMap": true,
"tsBuildInfoFile": "dist/.tsbuildinfo",
"rootDir": "src",
Expand Down
Loading