mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-08 12:28:05 +00:00
Run block fill for watcher automatically (#479)
* Find minimum start block number * Perform fill if db is empty * Make getStartBlock method public in GraphWatcher * Use dataSources property * Update server template to fill block on start * Avoid passing graphWatcher from generated watcher * Ensure block filling for non-subgraph watchers as well * Remove getStartBlock method from GraphWatcher * Remove graphWatcher property from ServerCmd --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
parent
07c0827a2a
commit
7b19d383ec
@ -29,7 +29,8 @@ import {
|
||||
PaymentsManager,
|
||||
Consensus,
|
||||
readParty,
|
||||
UpstreamConfig
|
||||
UpstreamConfig,
|
||||
fillBlocks
|
||||
} from '@cerc-io/util';
|
||||
import { TypeSource } from '@graphql-tools/utils';
|
||||
import type {
|
||||
@ -44,7 +45,7 @@ import { utils } from '@cerc-io/nitro-node';
|
||||
import type { Libp2p } from '@cerc-io/libp2p';
|
||||
|
||||
import { BaseCmd } from './base';
|
||||
import { readPeerId } from './utils/index';
|
||||
import { readPeerId, getStartBlock } from './utils/index';
|
||||
|
||||
const log = debug('vulcanize:server');
|
||||
|
||||
@ -284,6 +285,22 @@ export class ServerCmd {
|
||||
assert(indexer);
|
||||
assert(eventWatcher);
|
||||
|
||||
const syncStatus = await indexer.getSyncStatus();
|
||||
if (!syncStatus) {
|
||||
const contracts = await this.database.getContracts();
|
||||
const startBlock = getStartBlock(contracts);
|
||||
await fillBlocks(
|
||||
jobQueue,
|
||||
indexer,
|
||||
eventWatcher,
|
||||
config.jobQueue.blockDelayInMilliSecs,
|
||||
{
|
||||
startBlock,
|
||||
endBlock: startBlock
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (config.server.kind === KIND_ACTIVE) {
|
||||
// Delete all active and pending (before completed) jobs to prevent creating jobs after completion of processing previous block
|
||||
await jobQueue.deleteAllJobs('completed');
|
||||
|
@ -64,3 +64,20 @@ export const initClients = async (config: Config): Promise<{
|
||||
ethProvider
|
||||
};
|
||||
};
|
||||
|
||||
export const getStartBlock = (contracts: any[]): number => {
|
||||
if (!contracts || contracts.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let minStartingBlock = contracts[0].startingBlock;
|
||||
|
||||
for (let i = 1; i < contracts.length; i++) {
|
||||
const currentStartingBlock = contracts[i].startingBlock;
|
||||
if (currentStartingBlock < minStartingBlock) {
|
||||
minStartingBlock = currentStartingBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return minStartingBlock;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user