mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-08-01 20:22:07 +00:00
Log time taken for processing single block inside job-runner (#321)
This commit is contained in:
parent
01fa6e2184
commit
5dc6582ec8
@ -74,7 +74,16 @@ export const processBlockByNumber = async (
|
||||
|
||||
// Stop blocks already pushed to job queue. They are already retried after fail.
|
||||
if (!syncStatus || syncStatus.chainHeadBlockNumber < blockNumber) {
|
||||
await jobQueue.pushJob(QUEUE_BLOCK_PROCESSING, { kind: JOB_KIND_INDEX, blockHash, blockNumber, parentHash, timestamp });
|
||||
await jobQueue.pushJob(
|
||||
QUEUE_BLOCK_PROCESSING,
|
||||
{
|
||||
kind: JOB_KIND_INDEX,
|
||||
blockNumber: Number(blockNumber),
|
||||
blockHash,
|
||||
parentHash,
|
||||
timestamp
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,6 @@ export const fillBlocks = async (
|
||||
await eventWatcher.initEventProcessingOnCompleteHandler();
|
||||
|
||||
const numberOfBlocks = endBlock - startBlock + 1;
|
||||
console.time(`time:fill#fillBlocks-process_block_${startBlock}`);
|
||||
|
||||
processBlockByNumber(jobQueue, indexer, blockDelayInMilliSecs, startBlock);
|
||||
|
||||
@ -65,10 +64,6 @@ export const fillBlocks = async (
|
||||
const { onBlockProgressEvent: { blockNumber, isComplete } } = data;
|
||||
|
||||
if (isComplete) {
|
||||
console.timeEnd(`time:fill#fillBlocks-process_block_${blockNumber}`);
|
||||
|
||||
console.time(`time:fill#fillBlocks-process_block_${blockNumber + 1}`);
|
||||
|
||||
const blocksProcessed = blockNumber - startBlock + 1;
|
||||
const completePercentage = Math.round(blocksProcessed / numberOfBlocks * 100);
|
||||
log(`Processed ${blocksProcessed} of ${numberOfBlocks} blocks (${completePercentage}%)`);
|
||||
|
@ -22,6 +22,7 @@ export class JobRunner {
|
||||
_indexer: IndexerInterface
|
||||
_jobQueue: JobQueue
|
||||
_jobQueueConfig: JobQueueConfig
|
||||
_blockProcessStartTime?: Date
|
||||
|
||||
constructor (jobQueueConfig: JobQueueConfig, indexer: IndexerInterface, jobQueue: JobQueue) {
|
||||
this._jobQueueConfig = jobQueueConfig;
|
||||
@ -116,9 +117,18 @@ export class JobRunner {
|
||||
}
|
||||
|
||||
async _indexBlock (job: any): Promise<void> {
|
||||
const { data: { blockHash, blockNumber, parentHash, priority, timestamp } } = job;
|
||||
|
||||
const indexBlockStartTime = new Date();
|
||||
|
||||
const { data: { blockHash, blockNumber, parentHash, priority, timestamp } } = job;
|
||||
// Log time taken to complete processing of previous block.
|
||||
if (this._blockProcessStartTime) {
|
||||
const blockProcessDuration = indexBlockStartTime.getTime() - this._blockProcessStartTime.getTime();
|
||||
log(`time:job-runner#_indexBlock-process-block-${blockNumber - 1}: ${blockProcessDuration}ms`);
|
||||
log(`Total block process time (${blockNumber - 1}): ${blockProcessDuration}ms`);
|
||||
}
|
||||
|
||||
this._blockProcessStartTime = indexBlockStartTime;
|
||||
log(`Processing block number ${blockNumber} hash ${blockHash} `);
|
||||
|
||||
const syncStatus = await this._indexer.updateSyncStatusChainHead(blockHash, blockNumber);
|
||||
@ -218,9 +228,9 @@ export class JobRunner {
|
||||
async _processEvents (job: any): Promise<void> {
|
||||
const { blockHash } = job.data;
|
||||
|
||||
console.time('time:job-runner#_processEvents-get-block-process');
|
||||
console.time('time:job-runner#_processEvents-get-block-progress');
|
||||
let block = await this._indexer.getBlockProgress(blockHash);
|
||||
console.timeEnd('time:job-runner#_processEvents-get-block-process');
|
||||
console.timeEnd('time:job-runner#_processEvents-get-block-progress');
|
||||
assert(block);
|
||||
|
||||
console.time('time:job-runner#_processEvents-events');
|
||||
|
Loading…
Reference in New Issue
Block a user