-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest-api-server): add swarm stamp syncer
- Loading branch information
Showing
5 changed files
with
61 additions
and
43 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,5 @@ | ||
--- | ||
"@blobscan/rest-api-server": minor | ||
--- | ||
|
||
Added Swarm stamp syncer |
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 |
---|---|---|
@@ -1,32 +1,62 @@ | ||
/* eslint-disable @typescript-eslint/no-misused-promises */ | ||
|
||
import type { BaseSyncer } from "@blobscan/syncers"; | ||
import { | ||
DailyStatsSyncer, | ||
OverallStatsSyncer, | ||
SwarmStampSyncer, | ||
createRedisConnection, | ||
} from "@blobscan/syncers"; | ||
|
||
import { env } from "./env"; | ||
import { logger } from "./logger"; | ||
import { getNetworkDencunForkSlot } from "./utils"; | ||
|
||
export function setUpSyncers() { | ||
const connection = createRedisConnection(env.REDIS_URI); | ||
const syncers: BaseSyncer[] = []; | ||
|
||
if (env.SWARM_STORAGE_ENABLED) { | ||
if (!env.SWARM_BATCH_ID) { | ||
logger.warn(`Swarm stamp syncer not created: no batch ID provided`); | ||
} else if (!env.BEE_ENDPOINT) { | ||
logger.warn("Swarm stamp syncer not created: no Bee endpoint provided"); | ||
} else { | ||
syncers.push( | ||
new SwarmStampSyncer({ | ||
cronPattern: env.SYNCER_SWARM_STAMP_CRON_PATTERN, | ||
redisUriOrConnection: connection, | ||
batchId: env.SWARM_BATCH_ID, | ||
beeEndpoint: env.BEE_ENDPOINT, | ||
}) | ||
); | ||
} | ||
} | ||
|
||
const dailyStatsSyncer = new DailyStatsSyncer({ | ||
cronPattern: env.STATS_SYNCER_DAILY_CRON_PATTERN, | ||
redisUriOrConnection: connection, | ||
}); | ||
syncers.push( | ||
new DailyStatsSyncer({ | ||
cronPattern: env.STATS_SYNCER_DAILY_CRON_PATTERN, | ||
redisUriOrConnection: connection, | ||
}) | ||
); | ||
|
||
const overallStatsSyncer = new OverallStatsSyncer({ | ||
cronPattern: env.STATS_SYNCER_OVERALL_CRON_PATTERN, | ||
redisUriOrConnection: connection, | ||
lowestSlot: | ||
env.DENCUN_FORK_SLOT ?? getNetworkDencunForkSlot(env.NETWORK_NAME), | ||
}); | ||
syncers.push( | ||
new OverallStatsSyncer({ | ||
cronPattern: env.STATS_SYNCER_OVERALL_CRON_PATTERN, | ||
redisUriOrConnection: connection, | ||
lowestSlot: | ||
env.DENCUN_FORK_SLOT ?? getNetworkDencunForkSlot(env.NETWORK_NAME), | ||
}) | ||
); | ||
|
||
Promise.all([dailyStatsSyncer.start(), overallStatsSyncer.start()]); | ||
Promise.all(syncers.map((syncer) => syncer.start())); | ||
|
||
return () => { | ||
return dailyStatsSyncer.close().finally(() => overallStatsSyncer.close()); | ||
let teardownPromise = Promise.resolve(); | ||
|
||
for (const syncer of syncers) { | ||
teardownPromise = teardownPromise.finally(() => syncer.close()); | ||
} | ||
|
||
return teardownPromise; | ||
}; | ||
} |
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