Refactor code to initialize clients (#290)

* Refactor CLI code

* Refactor code to initialize clients

* Don't return config from function to initialize clients
This commit is contained in:
prathamesh0
2021-12-28 16:08:04 +05:30
committed by nabarun
parent a846917f1d
commit bb1345c696
27 changed files with 162 additions and 627 deletions
+1 -1
View File
@@ -12,5 +12,5 @@ export * from './src/events';
export * from './src/types';
export * from './src/indexer';
export * from './src/job-runner';
export * from './src/ipld-helper';
export * from './src/graph-decimal';
export * from './src/ipldHelper';
+4 -9
View File
@@ -9,9 +9,9 @@ import toml from 'toml';
import debug from 'debug';
import { ConnectionOptions } from 'typeorm';
import { BaseProvider } from '@ethersproject/providers';
import { Config as CacheConfig, getCache } from '@vulcanize/cache';
import { EthClient } from '@vulcanize/ipld-eth-client';
import { BaseProvider } from '@ethersproject/providers';
import { getCustomProvider } from './misc';
@@ -73,10 +73,7 @@ export const getConfig = async (configFile: string): Promise<Config> => {
return config;
};
export const getResetConfig = async (config: Config): Promise<{
dbConfig: ConnectionOptions,
serverConfig: ServerConfig,
upstreamConfig: UpstreamConfig,
export const initClients = async (config: Config): Promise<{
ethClient: EthClient,
postgraphileClient: EthClient,
ethProvider: BaseProvider
@@ -85,9 +82,10 @@ export const getResetConfig = async (config: Config): Promise<{
assert(serverConfig, 'Missing server config');
assert(dbConfig, 'Missing database config');
assert(upstreamConfig, 'Missing upstream config');
const { ethServer: { gqlApiEndpoint, gqlPostgraphileEndpoint, rpcProviderEndpoint }, cache: cacheConfig } = upstreamConfig;
assert(gqlApiEndpoint, 'Missing upstream ethServer.gqlApiEndpoint');
assert(gqlPostgraphileEndpoint, 'Missing upstream ethServer.gqlPostgraphileEndpoint');
assert(rpcProviderEndpoint, 'Missing upstream ethServer.rpcProviderEndpoint');
@@ -108,9 +106,6 @@ export const getResetConfig = async (config: Config): Promise<{
const ethProvider = getCustomProvider(rpcProviderEndpoint);
return {
dbConfig,
serverConfig,
upstreamConfig,
ethClient,
postgraphileClient,
ethProvider
+2 -4
View File
@@ -6,7 +6,7 @@ import assert from 'assert';
import debug from 'debug';
import { In } from 'typeorm';
import { JobQueueConfig, ServerConfig } from './config';
import { JobQueueConfig } from './config';
import {
JOB_KIND_INDEX,
JOB_KIND_PRUNE,
@@ -32,13 +32,11 @@ export class JobRunner {
_jobQueue: JobQueue
_jobQueueConfig: JobQueueConfig
_blockProcessStartTime?: Date
_serverConfig: ServerConfig
constructor (jobQueueConfig: JobQueueConfig, serverConfig: ServerConfig, indexer: IndexerInterface, jobQueue: JobQueue) {
constructor (jobQueueConfig: JobQueueConfig, indexer: IndexerInterface, jobQueue: JobQueue) {
this._indexer = indexer;
this._jobQueue = jobQueue;
this._jobQueueConfig = jobQueueConfig;
this._serverConfig = serverConfig;
}
async processBlock (job: any): Promise<void> {