Skip to content

Commit

Permalink
save and restore reports in batch minting script
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Nov 3, 2024
1 parent f96da0f commit 5461e0e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/scripts/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export function getReportsSubDir() {
reportsSubDir += '/output';
return reportsSubDir;
}

export const reportFilesDir = path.join(repoLocalDir, getReportsSubDir());
20 changes: 16 additions & 4 deletions src/scripts/runFundingPotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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.');
Expand Down
3 changes: 1 addition & 2 deletions src/scripts/syncDataWithJsonReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 5461e0e

Please sign in to comment.