@@ -5,6 +5,7 @@ import { dispatch, DispatchInfo } from "../../jobs/publisher-job";
55import { uint64ToInt64 } from "../../utils/int-uint-64" ;
66import Block , { BlockAttributes } from "../../models/block" ;
77import { sequelize } from "../../config/database" ;
8+ import StreamingError from "../../models/streaming-error" ;
89
910const SYNC_BASE_URL = getRequiredEnvString ( "SYNC_BASE_URL" ) ;
1011const SYNC_NETWORK = getRequiredEnvString ( "SYNC_NETWORK" ) ;
@@ -44,26 +45,39 @@ export async function startStreaming() {
4445 blocksToProcess . push ( b ) ;
4546 }
4647
48+ console . log ( "Processing blocks:" , blocksToProcess . length ) ;
4749 const promises = blocksToProcess . map ( async ( block : any ) => {
48- try {
49- return saveBlock ( block ) ;
50- } catch ( error ) {
51- console . error ( "Error saving block:" , error ) ;
50+ const blockData = await saveBlock ( block ) ;
51+ if ( blockData === null ) {
52+ await StreamingError . create ( {
53+ hash : block . header . hash ,
54+ chainId : block . header . chainId ,
55+ } ) ;
5256 }
57+ return blockData ;
5358 } ) ;
5459
55- const res = ( await Promise . all ( promises ) ) . filter (
56- ( r ) => r !== null ,
60+ const processed = ( await Promise . all ( promises ) ) . filter (
61+ ( r ) => r !== null || r !== undefined ,
5762 ) as DispatchInfo [ ] ;
5863
59- const dispatches = res . map ( async ( r , index ) => {
60- await dispatch ( r ) ;
61- await delay ( 500 ) ;
62- console . log ( "Dispatched block:" , index ) ;
64+ const dispatches = processed . map ( async ( r ) => {
65+ try {
66+ await delay ( 500 ) ;
67+ await dispatch ( r ) ;
68+ } catch ( err ) {
69+ console . error ( "Error dispatching block:" , err ) ;
70+ }
6371 } ) ;
6472
6573 await Promise . all ( dispatches ) ;
66- console . log ( "Done processing blocks: " , blocksToProcess . length ) ;
74+ console . log (
75+ "Processed:" ,
76+ processed . length ,
77+ "|" ,
78+ "Dispatched:" ,
79+ dispatches . length ,
80+ ) ;
6781 } , 1000 * 10 ) ;
6882
6983 setInterval (
0 commit comments