Skip to content

Commit

Permalink
feat: circuit break on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Mar 29, 2024
1 parent af69ed7 commit ac1f685
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 46 deletions.
2 changes: 2 additions & 0 deletions cli/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export function activateHandler() {
} catch (e) {
console.error('Aggregator was not activated. Reason:')
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand Down Expand Up @@ -311,6 +312,7 @@ export function deactivateHandler() {
} catch (e) {
console.error('Aggregator was not deactivated. Reason:')
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand Down
108 changes: 62 additions & 46 deletions cli/src/datafeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,28 +286,36 @@ export function bulkActivateHandler() {
continue
}

await fetcherStartHandler()({
id: aggregatorData.aggregatorHash,
chain,
host: fetcherHost,
port: fetcherPort
})
await aggregatorActivateHandler()({
aggregatorHash: aggregatorData.aggregatorHash,
host: workerHost,
port: workerPort
})

await reporterActivateHandler()({
id: Number(reporterId),
host: reporterHost,
port: reporterPort
})
await listenerActivateHandler()({
id: Number(listenerId),
host: listenerHost,
port: listenerPort
})
try {
await fetcherStartHandler()({
id: aggregatorData.aggregatorHash,
chain,
host: fetcherHost,
port: fetcherPort
})
await aggregatorActivateHandler()({
aggregatorHash: aggregatorData.aggregatorHash,
host: workerHost,
port: workerPort
})

await reporterActivateHandler()({
id: Number(reporterId),
host: reporterHost,
port: reporterPort
})
await listenerActivateHandler()({
id: Number(listenerId),
host: listenerHost,
port: listenerPort
})
} catch (e) {
console.error(
`activation failed for ${activateElement.aggregatorSource}, breaking iteration`
)
console.error(e?.response?.data)
break
}
}
}
return wrapper
Expand Down Expand Up @@ -364,30 +372,38 @@ export function bulkDeactivateHandler() {
continue
}

await listenerDeactivateHandler()({
id: Number(listenerId),
host: listenerHost,
port: listenerPort
})

await reporterDeactivateHandler()({
id: Number(reporterId),
host: reporterHost,
port: reporterPort
})

await aggregatorDeactivateHandler()({
aggregatorHash: aggregatorData.aggregatorHash,
host: workerHost,
port: workerPort
})

await fetcherStopHandler()({
id: aggregatorData.aggregatorHash,
chain,
host: fetcherHost,
port: fetcherPort
})
try {
await listenerDeactivateHandler()({
id: Number(listenerId),
host: listenerHost,
port: listenerPort
})

await reporterDeactivateHandler()({
id: Number(reporterId),
host: reporterHost,
port: reporterPort
})

await aggregatorDeactivateHandler()({
aggregatorHash: aggregatorData.aggregatorHash,
host: workerHost,
port: workerPort
})

await fetcherStopHandler()({
id: aggregatorData.aggregatorHash,
chain,
host: fetcherHost,
port: fetcherPort
})
} catch (e) {
console.error(
`deactivation failed for ${deactivateElement.aggregatorSource}, breaking iteration`
)
console.error(e?.response?.data)
break
}
}
}
return wrapper
Expand Down
2 changes: 2 additions & 0 deletions cli/src/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export function startHandler() {
console.log(result)
} catch (e) {
console.error(e?.response?.data, { depth: null })
throw e
}
}
return wrapper
Expand All @@ -144,6 +145,7 @@ export function stopHandler() {
console.log(result)
} catch (e) {
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand Down
2 changes: 2 additions & 0 deletions cli/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export function activateHandler() {
} catch (e) {
console.error('Listener was not activated. Reason:')
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand All @@ -249,6 +250,7 @@ export function deactivateHandler() {
} catch (e) {
console.error('Listener was not deactivated. Reason:')
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand Down
2 changes: 2 additions & 0 deletions cli/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export function activateHandler() {
} catch (e) {
console.error('Reporter was not activated. Reason:')
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand All @@ -274,6 +275,7 @@ export function deactivateHandler() {
} catch (e) {
console.error('Reporter was not deactivated. Reason:')
console.error(e?.response?.data?.message)
throw e
}
}
return wrapper
Expand Down

0 comments on commit ac1f685

Please sign in to comment.