diff --git a/src/scripts/configs.ts b/src/scripts/configs.ts index 9640f181e..34114d40c 100644 --- a/src/scripts/configs.ts +++ b/src/scripts/configs.ts @@ -19,3 +19,5 @@ export function getReportsSubDir() { reportsSubDir += '/output'; return reportsSubDir; } + +export const reportFilesDir = path.join(repoLocalDir, getReportsSubDir()); diff --git a/src/scripts/runFundingPotService.ts b/src/scripts/runFundingPotService.ts index fb6c29401..42f5dc04f 100644 --- a/src/scripts/runFundingPotService.ts +++ b/src/scripts/runFundingPotService.ts @@ -3,7 +3,7 @@ import { spawn } from 'child_process'; import path from 'path'; import fs from 'fs-extra'; import simpleGit from 'simple-git'; -import { repoLocalDir, repoUrl } from './configs'; +import { repoLocalDir, reportFilesDir, repoUrl } from './configs'; import config from '../config'; import { Project } from '../entities/project'; import { AppDataSource } from '../orm'; @@ -17,6 +17,7 @@ import { EarlyAccessRound } from '../entities/earlyAccessRound'; import { findAllEarlyAccessRounds } from '../repositories/earlyAccessRoundRepository'; import { findQfRounds } from '../repositories/qfRoundRepository'; import { updateRewardsForDonations } from './syncDataWithJsonReport'; +import { restoreReportsFromDB, saveReportsToDB } from './reportService'; // Attention: the configs of batches should be saved in the funding pot repo // this script pulls the latest version of funding pot service, @@ -223,7 +224,13 @@ async function installDependencies() { async function runFundingPotService(batchNumber: number) { const command = 'npm run all ' + batchNumber; console.info(`Running "${command}" in ${serviceDir}...`); - await execShellCommand(command, serviceDir); + try { + await execShellCommand(command, serviceDir); + } catch (e) { + console.error('Error in funding pot execution:', e); + } + console.info('Saving reports to the DB...'); + await saveReportsToDB(reportFilesDir); } async function getFirstRoundThatNeedExecuteBatchMinting() { @@ -341,16 +348,21 @@ async function main() { console.info('Env file created successfully.'); // Step 5 + console.info('Restoring previous report files...'); + await restoreReportsFromDB(reportFilesDir); + console.info('Previous report files restored successfully!'); + + // Step 6 console.info('Running funding pot service...'); await runFundingPotService(batchNumber); console.info('Funding pot service executed successfully!'); - // Step 6 + // Step 7 console.info('Setting batch minting execution flag in round data...'); await setBatchMintingExecutionFlag(batchNumber); console.info('Batch minting execution flag set successfully.'); - // Step 7 + // Step 8 console.info('Start Syncing reward data in donations...'); await updateRewardsForDonations(batchNumber); console.info('Rewards data synced successfully.'); diff --git a/src/scripts/syncDataWithJsonReport.ts b/src/scripts/syncDataWithJsonReport.ts index 505502c81..72e4c6a0c 100644 --- a/src/scripts/syncDataWithJsonReport.ts +++ b/src/scripts/syncDataWithJsonReport.ts @@ -7,7 +7,7 @@ import { Donation } from '../entities/donation'; import { Project } from '../entities/project'; import { AppDataSource } from '../orm'; import { getStreamDetails } from './helpers'; -import { repoLocalDir, getReportsSubDir } from './configs'; +import { reportFilesDir } from './configs'; async function loadReportFile(filePath: string) { try { @@ -127,7 +127,6 @@ export async function updateRewardsForDonations(batchNumber: number) { const donationsByProjectId = _.groupBy(donations, 'projectId'); - const reportFilesDir = path.join(repoLocalDir, getReportsSubDir()); const allReportFiles = getAllReportFiles(reportFilesDir); for (const projectId of Object.keys(donationsByProjectId)) {