-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from ckb-cell/feat/utxo-and-cell-cache
feat: add data cache for UTXO and RGB++ asset cells
- Loading branch information
Showing
22 changed files
with
1,152 additions
and
151 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import pino from 'pino'; | ||
import { FastifyPluginCallback } from 'fastify'; | ||
import { Server } from 'http'; | ||
import { ZodTypeProvider } from 'fastify-type-provider-zod'; | ||
import container from '../../container'; | ||
import { VERCEL_MAX_DURATION } from '../../constants'; | ||
import RgbppCollector from '../../services/rgbpp'; | ||
|
||
const collectRgbppCellsCronRoute: FastifyPluginCallback<Record<never, never>, Server, ZodTypeProvider> = ( | ||
fastify, | ||
_, | ||
done, | ||
) => { | ||
fastify.get( | ||
'/collect-rgbpp-cells', | ||
{ | ||
schema: { | ||
tags: ['Cron Task'], | ||
description: 'Run UTXO sync cron task to update data cache, used for serverless deployment', | ||
}, | ||
}, | ||
async () => { | ||
const logger = container.resolve<pino.BaseLogger>('logger'); | ||
const rgbppCollector: RgbppCollector = container.resolve('rgbppCollector'); | ||
try { | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, (VERCEL_MAX_DURATION - 10) * 1000); | ||
rgbppCollector.startProcess({ | ||
onActive: (job) => { | ||
logger.info(`[rgbppCollector] Job active: ${job.id}`); | ||
}, | ||
onCompleted: (job) => { | ||
logger.info(`[rgbppCollector] Job completed: ${job.id}`); | ||
}, | ||
}); | ||
}); | ||
await rgbppCollector.pauseProcess(); | ||
await rgbppCollector.closeProcess(); | ||
} catch (err) { | ||
logger.error(err); | ||
fastify.Sentry.captureException(err); | ||
} | ||
}, | ||
); | ||
done(); | ||
}; | ||
|
||
export default collectRgbppCellsCronRoute; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pino from 'pino'; | ||
import { FastifyPluginCallback } from 'fastify'; | ||
import { Server } from 'http'; | ||
import { ZodTypeProvider } from 'fastify-type-provider-zod'; | ||
import container from '../../container'; | ||
import { VERCEL_MAX_DURATION } from '../../constants'; | ||
import UTXOSyncer from '../../services/utxo'; | ||
|
||
const syncUTXOCronRoute: FastifyPluginCallback<Record<never, never>, Server, ZodTypeProvider> = (fastify, _, done) => { | ||
fastify.get( | ||
'/sync-utxo', | ||
{ | ||
schema: { | ||
tags: ['Cron Task'], | ||
description: 'Run UTXO sync cron task to update data cache, used for serverless deployment', | ||
}, | ||
}, | ||
async () => { | ||
const logger = container.resolve<pino.BaseLogger>('logger'); | ||
const utxoSyncer: UTXOSyncer = container.resolve('utxoSyncer'); | ||
try { | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, (VERCEL_MAX_DURATION - 10) * 1000); | ||
utxoSyncer.startProcess({ | ||
onActive: (job) => { | ||
logger.info(`[UTXOSyncer] Job active: ${job.id}`); | ||
}, | ||
onCompleted: (job) => { | ||
logger.info(`[UTXOSyncer] Job completed: ${job.id}`); | ||
}, | ||
}); | ||
}); | ||
await utxoSyncer.pauseProcess(); | ||
await utxoSyncer.closeProcess(); | ||
} catch (err) { | ||
logger.error(err); | ||
fastify.Sentry.captureException(err); | ||
} | ||
}, | ||
); | ||
done(); | ||
}; | ||
|
||
export default syncUTXOCronRoute; |
Oops, something went wrong.