[offers][fix] Extract seed analysis out and make it sequential

pull/522/head
Bryann Yeap Kok Keong 2 years ago
parent 373480b9e1
commit 1dda831c54

@ -11,6 +11,7 @@
"postinstall": "prisma generate", "postinstall": "prisma generate",
"seed": "ts-node prisma/seed.ts", "seed": "ts-node prisma/seed.ts",
"seed-salaries": "ts-node prisma/seed-salaries.ts", "seed-salaries": "ts-node prisma/seed-salaries.ts",
"seed-analysis": "ts-node prisma/seed-analysis.ts",
"seed-questions": "ts-node prisma/seed-questions.ts" "seed-questions": "ts-node prisma/seed-questions.ts"
}, },
"dependencies": { "dependencies": {

@ -0,0 +1,37 @@
import { PrismaClient } from '@prisma/client';
import { generateAnalysis } from '../src/utils/offers/analysis/analysisGeneration';
const prisma = new PrismaClient();
const seedAnalysis = async () => {
console.log('Busy crunching analysis.....');
const profilesWithoutAnalysis = await prisma.offersProfile.findMany({
where: {
analysis: {
is: null,
},
},
});
for (const profile of profilesWithoutAnalysis) {
await generateAnalysis({
ctx: { prisma, session: null },
input: { profileId: profile.id },
});
console.log('Analysis generated for profile with id:', profile.id);
}
};
Promise.all([seedAnalysis()])
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
console.log('Analysis stopping!');
await prisma.$disconnect();
process.exit(1);
});
export {};

@ -3,7 +3,6 @@ import { PrismaClient } from '@prisma/client';
import crypto from 'crypto'; import crypto from 'crypto';
import { baseCurrencyString } from '../src/utils/offers/currency'; import { baseCurrencyString } from '../src/utils/offers/currency';
import { convert } from '../src/utils/offers/currency/currencyExchange'; import { convert } from '../src/utils/offers/currency/currencyExchange';
import { generateAnalysis } from '../src/utils/offers/analysis/analysisGeneration';
import { import {
generateRandomName, generateRandomName,
@ -344,26 +343,9 @@ const seedSalaries = async () => {
} }
}; };
const generateAllAnalysis = async () => {
return await Promise.all(
createdProfileIds.map(async (profileId) => {
await generateAnalysis({
ctx: { prisma, session: null },
input: { profileId },
});
console.log('Analysis generated for profile with id:', profileId);
}),
);
};
Promise.all([seedSalaries()]) Promise.all([seedSalaries()])
.then(() => { .then(() => {
console.log(createdProfileIds.length + ' profiles created'); console.log(createdProfileIds.length + ' profiles created');
console.log('Busy crunching analysis.....');
})
.then(() => generateAllAnalysis())
.then((_data) => {
console.log('Seeding from salaries sheet complete');
}) })
.then(async () => { .then(async () => {
await prisma.$disconnect(); await prisma.$disconnect();

Loading…
Cancel
Save