mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
hotfix restart gradido node if it don't get new transaction after 1 second
This commit is contained in:
parent
f716c92fe9
commit
f66f33307d
@ -97,6 +97,10 @@ export class GradidoNodeProcess {
|
||||
}
|
||||
}
|
||||
|
||||
public getLastStarted(): Date | null {
|
||||
return this.lastStarted
|
||||
}
|
||||
|
||||
public async exit(): Promise<void> {
|
||||
this.exitCalled = true
|
||||
if (this.proc) {
|
||||
|
||||
@ -22,6 +22,9 @@ import { CONFIG } from '../../config'
|
||||
import { LOG4JS_BASE_CATEGORY } from '../../config/const'
|
||||
import { HieroId, hieroIdSchema } from '../../schemas/typeGuard.schema'
|
||||
import { type TopicInfoOutput, topicInfoSchema } from './output.schema'
|
||||
import { GradidoNodeClient } from '../GradidoNode/GradidoNodeClient'
|
||||
import { GradidoNodeProcess } from '../GradidoNode/GradidoNodeProcess'
|
||||
import { printTimeDuration } from '../../utils/time'
|
||||
|
||||
// https://docs.hedera.com/hedera/sdks-and-apis/hedera-api/consensus/consensusupdatetopic
|
||||
export const MIN_AUTORENEW_PERIOD = 6999999 //seconds
|
||||
@ -95,6 +98,27 @@ export class HieroClient {
|
||||
logger.info(
|
||||
`message sent to topic ${topicId}, transaction id: ${sendResponse.transactionId.toString()}`,
|
||||
)
|
||||
// TODO: fix issue in GradidoNode
|
||||
// hot fix, when gradido node is running some time, the hiero listener stop working, so we check if our new transaction is received
|
||||
// after 1 second, else restart GradidoNode
|
||||
setTimeout(async () => {
|
||||
const transaction = await GradidoNodeClient.getInstance().getTransaction({
|
||||
topic: topicId,
|
||||
hieroTransactionId: sendResponse.transactionId.toString(),
|
||||
})
|
||||
if (!transaction) {
|
||||
const process = GradidoNodeProcess.getInstance()
|
||||
const lastStarted = process.getLastStarted()
|
||||
if (lastStarted) {
|
||||
const serverRunTime = printTimeDuration(new Date().getTime() - lastStarted.getTime())
|
||||
this.logger.error(`transaction not found, restart GradidoNode after ${serverRunTime}`)
|
||||
await GradidoNodeProcess.getInstance().restart()
|
||||
} else {
|
||||
this.logger.error('transaction not found, GradidoNode not running, start it')
|
||||
GradidoNodeProcess.getInstance().start()
|
||||
}
|
||||
}
|
||||
}, 1000)
|
||||
if (logger.isInfoEnabled()) {
|
||||
// only for logging
|
||||
sendResponse.getReceiptWithSigner(this.wallet).then((receipt) => {
|
||||
|
||||
42
dlt-connector/src/utils/time.ts
Normal file
42
dlt-connector/src/utils/time.ts
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @param {number} time - in minutes
|
||||
*/
|
||||
export const getTimeDurationObject = (
|
||||
time: number,
|
||||
): {
|
||||
hours?: number
|
||||
minutes: number
|
||||
} => {
|
||||
if (time > 60) {
|
||||
return {
|
||||
hours: Math.floor(time / 60),
|
||||
minutes: time % 60,
|
||||
}
|
||||
}
|
||||
return { minutes: time }
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @returns duration in minutes
|
||||
*/
|
||||
export const durationInMinutesFromDates = (startDate: Date, endDate: Date): number => {
|
||||
const diff = endDate.getTime() - startDate.getTime()
|
||||
return Math.floor(diff / (1000 * 60))
|
||||
}
|
||||
|
||||
/**
|
||||
* @param duration in minutes
|
||||
*/
|
||||
export const printTimeDuration = (duration: number): string => {
|
||||
const time = getTimeDurationObject(duration)
|
||||
const result = time.minutes > 0 ? `${time.minutes} minutes` : ''
|
||||
if (time.hours) {
|
||||
return `${time.hours} hours` + (result !== '' ? ` and ${result}` : '')
|
||||
}
|
||||
if (result === '') {
|
||||
return '0 minutes'
|
||||
}
|
||||
return result
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user