Skip to content

Commit

Permalink
#38: added option to skip firest n reports
Browse files Browse the repository at this point in the history
useful in case of an error where the program gets stuck due to network issues. we can now skip the reports already downloaded and continue where we the program hanged.
  • Loading branch information
mohit-s96 committed Oct 3, 2023
1 parent 942a79e commit a6793e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ program
.option('-p, --pathToBackup <string>', 'Path where to store the backup of the reports.')
.option('-d, --dataDictionary', 'Flag to only backup the data dictionary and data availability reports.')
.option('-w, --webApi', 'Flag to only backup the web api reports.')
.option('-s, --skip <number>', 'Option to skip first n number of reports')
.description('Backs up the reports from a Cert API server to a specified path.')
.action(backup);

Expand Down
10 changes: 7 additions & 3 deletions lib/backup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function saveReportToDisk(report, backupPath, stats) {
}
}

const getAllDDAndDAReports = async (serverUrl, preFetchedDDReportIds, backupPath, stats) => {
const getAllDDAndDAReports = async (serverUrl, preFetchedDDReportIds, backupPath, stats, skip) => {
let ddReportIds = [];
let ddReports = 0;
let daReports = 0;
Expand All @@ -79,6 +79,9 @@ const getAllDDAndDAReports = async (serverUrl, preFetchedDDReportIds, backupPath
for (const id of ddReportIds) {
console.clear();
console.log(chalk.greenBright.bold(`Fetching report ${++count} of ${ddReportIds.length}`));
if (count < skip) {
continue;
}
const ddReport = await fetchSingleDDReport({ serverUrl, id });
const daReport = await fetchDataAvailabilityReport({ serverUrl, reportId: id });
ddReports++;
Expand All @@ -96,7 +99,7 @@ const getAllDDAndDAReports = async (serverUrl, preFetchedDDReportIds, backupPath
};

const backup = async (options = {}, preFetchedDDReportIds = []) => {
const { url = '', pathToBackup = '', dataDictionary = false, webApi = false } = options;
const { url = '', pathToBackup = '', dataDictionary = false, webApi = false, skip = 0 } = options;
if (!isValidUrl(url)) return;
const backupPath = path.join(pathToBackup, BACKUP_DIRECTORY);
try {
Expand Down Expand Up @@ -125,7 +128,8 @@ const backup = async (options = {}, preFetchedDDReportIds = []) => {
url,
preFetchedDDReportIds,
backupPath,
stats
stats,
skip
);
stats.ddReportsCount = ddReportsCount;
stats.daReportsCount = daReportsCount;
Expand Down

0 comments on commit a6793e0

Please sign in to comment.