Skip to content

Commit

Permalink
stop the cron job;
Browse files Browse the repository at this point in the history
Signed-off-by: tcar <[email protected]>
  • Loading branch information
tcar121293 committed Dec 7, 2023
1 parent 8d6600d commit 5e7aa5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/indexer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import { healthcheckRoute } from "./healthcheck"
import { OfacComplianceService } from "./services/ofac"
import AccountRepository from "./repository/account"
import CoinMarketCapService from "./services/coinmarketcap/coinmarketcap.service"
import { checkTransferStatus, startCronJob } from "./services/monitoringService"
import { checkTransferStatus, getCronJob } from "./services/monitoringService"
import { NotificationSender } from "./services/monitoringService/notificationSender"
import { CronJob } from "cron"

interface DomainIndexer {
listenToEvents(): Promise<void>
Expand Down Expand Up @@ -54,6 +55,7 @@ init()
})
.catch(err => logger.error("Error occurred during database closing: ", err))

initData.cron.stop()
nodeCleanup.uninstall()
return false
})
Expand All @@ -68,7 +70,7 @@ init()
logger.error("Error occurred on app initialization: ", reason)
})

async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: FastifyInstance }> {
async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: FastifyInstance, cron: CronJob }> {
const sharedConfig = await getSharedConfig(process.env.SHARED_CONFIG_URL!)

const chainAnalysisUrl = process.env.CHAIN_ANALYSIS_URL || ""
Expand Down Expand Up @@ -100,8 +102,8 @@ async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: Fast
const notificationSender = new NotificationSender(process.env.SNS_REGION!)

const cronTime = process.env.CRON_TIME || "* */10 * * * *"
startCronJob(cronTime, checkTransferStatus, transferRepository, notificationSender)

const cron = getCronJob(cronTime, checkTransferStatus, transferRepository, notificationSender)
cron.start()
for (const domain of domainsToIndex) {
const rpcURL = rpcUrlConfig.get(domain.id)
if (!rpcURL) {
Expand Down Expand Up @@ -153,7 +155,7 @@ async function init(): Promise<{ domainIndexers: Array<DomainIndexer>; app: Fast
}
}

return { domainIndexers, app }
return { domainIndexers, app, cron }
}

async function insertDomains(
Expand Down
5 changes: 2 additions & 3 deletions src/indexer/services/monitoringService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ export async function checkTransferStatus(transferRepository: TransferRepository
}
}

export function startCronJob(cronTime: string | Date | DateTime, fn: Function, ...args: Parameters<any>): void {
const cronJob = new CronJob(cronTime, () => {
export function startCronJob(cronTime: string | Date | DateTime, fn: Function, ...args: Parameters<any>): CronJob {
return new CronJob(cronTime, () => {
try {
fn(...args)
} catch (err) {
logger.error("Error while executing cron job function", err)
}
})
cronJob.start()
}

0 comments on commit 5e7aa5f

Please sign in to comment.