Skip to content

Commit

Permalink
emit sync event
Browse files Browse the repository at this point in the history
  • Loading branch information
hazelnutcloud committed May 19, 2023
1 parent 006eb60 commit 834f8ba
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.4.10
- fix: emit event when arkiver is synced
- - fix: set maxQueueSize to 3

# v0.4.9
- chore: add environment flag to deploy command

Expand Down
2 changes: 1 addition & 1 deletion cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './cli/mod.ts'
import 'https://deno.land/[email protected]/dotenv/load.ts'

export const version = 'v0.4.9'
export const version = 'v0.4.10'

const command = new Command()
.name('arkiver')
Expand Down
53 changes: 50 additions & 3 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/arkiver/arkiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class Arkiver extends EventTarget {
private readonly manifest: ArkiveManifest
private arkiveData: Arkive
private sources: DataSource[] = []
private syncedCount = 0
private mongoConnection?: string
private rpcUrls: Record<string, string>

Expand Down Expand Up @@ -73,6 +74,17 @@ export class Arkiver extends EventTarget {
noDb: this.mongoConnection === undefined,
arkiveMinorVersion: this.arkiveData.deployment.minor_version,
})

dataSource.addEventListener('synced', () => {
this.syncedCount++
if (this.syncedCount === Object.entries(dataSources).length) {
logger('arkiver').info(
`Arkiver synced - ${this.arkiveData.name}`,
)
this.dispatchEvent(new Event('synced'))
}
})

await dataSource.run()
this.sources.push(dataSource)
}
Expand Down
6 changes: 4 additions & 2 deletions src/arkiver/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface NormalizedContracts {
signatureTopics: string[]
}

export class DataSource {
export class DataSource extends EventTarget {
private readonly chain: keyof typeof supportedChains
private readonly rpcUrl: string
private readonly client: PublicClient<HttpTransport>
Expand Down Expand Up @@ -100,7 +100,7 @@ export class DataSource {
fetcher: true,
processor: true,
}
private maxQueueSize = 10
private maxQueueSize = 3
private liveDelay = 2000
private queueDelay = 500
private fetchInterval = 500
Expand All @@ -124,6 +124,7 @@ export class DataSource {
noDb: boolean
},
) {
super()
this.chain = params.chain
this.rpcUrl = params.rpcUrl
this.blockRange = params.blockRange
Expand Down Expand Up @@ -208,6 +209,7 @@ export class DataSource {

if (toBlock === this.liveBlockHeight && !this.isLive) {
this.isLive = true
this.dispatchEvent(new Event('synced'))
logger(this.chain).info(
`Start live arkiving for ${this.chain} at ${this.liveBlockHeight}`,
)
Expand Down

1 comment on commit 834f8ba

@vercel
Copy link

@vercel vercel bot commented on 834f8ba May 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.