Skip to content

Commit

Permalink
Fix query of getting failed donations from mongo API
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadranjbarz committed Jan 23, 2024
1 parent de14c4b commit 9c7d9cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/adapters/donationSaveBackup/donationSaveBackupAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class DonationSaveBackupAdapter implements DonationSaveBackupInterface {
dataSource: DONATION_SAVE_BACKUP_DATA_SOURCE,
limit: params.limit,
filter: {
imported: { $ne: true },
importError: { $ne: true },
imported: { $exists: false },
importError: { $exists: false },
},
sort: { _id: 1 },
},
Expand Down
14 changes: 14 additions & 0 deletions src/services/cronJobs/backupDonationImportJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,28 @@ export const runSyncBackupServiceDonations = () => {

// Mock Mongo Methods to write a test
export const importBackupServiceDonations = async () => {
logger.info('importBackupServiceDonations() has been called');
const limit = 10;
let donations =
await getDonationSaveBackupAdapter().getNotImportedDonationsFromBackup({
limit,
});
logger.info(
'importBackupServiceDonations() donations.length: ',
donations.length,
);
while (donations.length > 0) {
for (const donation of donations) {
try {
await createBackupDonation(donation);
await getDonationSaveBackupAdapter().markDonationAsImported(
donation._id,
);
logger.info('Failed donation has imported successfully', {
donationId: donation._id,
txHash: donation.txHash,
networkId: donation.chainId,
});
} catch (e) {
await getDonationSaveBackupAdapter().markDonationAsImportError(
donation._id,
Expand All @@ -50,6 +60,10 @@ export const importBackupServiceDonations = async () => {
await getDonationSaveBackupAdapter().getNotImportedDonationsFromBackup({
limit,
});
logger.info('importBackupServiceDonations() inside loop ', {
donationsLength: donations.length,
limit,
});
}
};

Expand Down

0 comments on commit 9c7d9cf

Please sign in to comment.