-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adea4db
commit feddc26
Showing
10 changed files
with
181 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const IS_DEBUG = process.env.DEBUG; | ||
const APP = process.env.APP; | ||
|
||
const commonOptions = { | ||
interpreter: 'tsx', | ||
node_args: IS_DEBUG ? ['--inspect-brk'] : [], | ||
watch: true, | ||
ignore_watch: ['node_modules'], | ||
}; | ||
|
||
module.exports = { | ||
apps: [ | ||
...(APP === 'graphql' | ||
? [ | ||
{ | ||
...commonOptions, | ||
name: 'graphql', | ||
script: './src/app.ts', | ||
}, | ||
] | ||
: []), | ||
...(APP === 'syncer' | ||
? [ | ||
{ | ||
...commonOptions, | ||
name: 'syncer', | ||
script: './src/syncer.ts', | ||
}, | ||
] | ||
: []), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import c from 'chalk'; | ||
import { uniqBy } from 'lodash'; | ||
import type { GQLBlock } from '~/graphql/generated/sdk'; | ||
import type { QueueData, QueueInputs, QueueNames } from '~/infra/queue/Queue'; | ||
import { pool } from '~/infra/worker/WorkerPool'; | ||
|
||
type Input = QueueInputs[QueueNames.SYNC_TRANSACTIONS]; | ||
export type SyncTransactionEvent = { | ||
index: number; | ||
block: GQLBlock; | ||
txHash: string; | ||
}; | ||
|
||
export class SyncTransactions { | ||
async execute({ data }: QueueData<Input>) { | ||
const { blocks } = data; | ||
const events = blocks.flatMap((block) => { | ||
const txs = uniqBy(block.transactions, 'id'); | ||
return txs.map<SyncTransactionEvent>((transaction, idx) => ({ | ||
index: idx, | ||
block: block, | ||
txHash: transaction.id, | ||
})); | ||
}); | ||
|
||
if (events.length) { | ||
const fromBlock = blocks[0].header.height; | ||
const toBlock = blocks[blocks.length - 1].header.height; | ||
const msg = `# Syncing ${events.length} transactions from ${fromBlock} to ${toBlock}`; | ||
console.log(c.gray(msg)); | ||
await pool.run({ data: events }); | ||
} | ||
} | ||
} | ||
|
||
export const syncTransactions = async (input: QueueData<Input>) => { | ||
try { | ||
const syncTransactions = new SyncTransactions(); | ||
await syncTransactions.execute(input); | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error('Sync transactions', { | ||
cause: error, | ||
}); | ||
} | ||
}; |
Oops, something went wrong.