Skip to content

Commit

Permalink
Check both IP and DN endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
shimkiv committed Jul 20, 2024
1 parent d815015 commit 1c9848e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
34 changes: 20 additions & 14 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

38 changes: 21 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export async function run(): Promise<void> {
const minaDaemonGraphQlPort = core.getInput('mina-graphql-port')
const maxAttempts = Number(core.getInput('max-attempts'))
const pollingIntervalMs = Number(core.getInput('polling-interval-ms'))
const minaDaemonGraphQlEndpoint = `http://127.0.0.1:${minaDaemonGraphQlPort}/graphql`
const minaDaemonGraphQlUrlWithIp = `http://127.0.0.1:${minaDaemonGraphQlPort}/graphql`
const minaDaemonGraphQlUrlWithDn = `http://localhost:${minaDaemonGraphQlPort}/graphql`
const syncStatusGraphQlQuery = {
query: '{ syncStatus }',
variables: null,
Expand All @@ -36,30 +37,33 @@ export async function run(): Promise<void> {
core.info(`polling-interval-ms: ${pollingIntervalMs}`)
core.info('\nWaiting for the blockchain network readiness.\n')

// Wait for the blockchain network to be ready to use
while (blockchainSyncAttempt <= maxAttempts && !blockchainIsReady) {
const checkEndpoint = async (url: string): Promise<boolean> => {
try {
const response = await new HttpClient(
'mina-network-action'
).postJson<GraphQlResponse>(
minaDaemonGraphQlEndpoint,
syncStatusGraphQlQuery
)
if (response.statusCode >= 400) {
await wait(pollingIntervalMs)
} else {
const response = await new HttpClient('mina-network-action', undefined, {
allowRedirects: true,
ignoreSslError: true
}).postJson<GraphQlResponse>(url, syncStatusGraphQlQuery)
if (response.statusCode < 400) {
const result = response.result
if (result?.data?.syncStatus === 'SYNCED') {
blockchainIsReady = true
} else {
await wait(pollingIntervalMs)
return true
}
}
} catch (_) {
// Ignore the errors.
}
return false
}

while (blockchainSyncAttempt <= maxAttempts && !blockchainIsReady) {
blockchainIsReady =
(await checkEndpoint(minaDaemonGraphQlUrlWithIp)) ||
(await checkEndpoint(minaDaemonGraphQlUrlWithDn))
if (!blockchainIsReady) {
logBlockchainIsNotReadyYet(pollingIntervalMs)
await wait(pollingIntervalMs)
blockchainSyncAttempt++
}
logBlockchainIsNotReadyYet(pollingIntervalMs)
blockchainSyncAttempt++
}
if (!blockchainIsReady) {
core.setFailed(
Expand Down

0 comments on commit 1c9848e

Please sign in to comment.