Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INFRA28 - Check a failing seeding script #237

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions seeding/check-seeding-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const checkSeedingStatus = async () => {
exit(1);
}
}
exit(0);
};

checkSeedingStatus();
3 changes: 2 additions & 1 deletion seeding/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"type": "commonjs",
"scripts": {
"seed": "node run-seeding.js"
"seed": "node src/run-seeding.js",
"check-seeding-status": "node src/check-seeding-status.js"
},
"dependencies": {
"loading-cli": "^1.1.2"
Expand Down
23 changes: 19 additions & 4 deletions seeding/run-seeding.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@ const { initializeApp } = require("./config");

initializeApp();

let someSeedFails = false;

const checkAndExecuteSeed = async (seed) => {
loader.start(`Checking if ${seed.description} was executed...`);
const isExecuted = await checkIfSeedWasExecuted(seed.key);
loader.stop();
if (!isExecuted) {
await seed.execute();
try {
await seed.execute();
} catch (error) {
someSeedFails = true;
loader.stop();
return;
}
loader.start("Updating seed status...");
await markSeedAsExecuted(seed.key);
loader.stop();
Expand All @@ -23,6 +31,7 @@ const checkAndExecuteSeed = async (seed) => {
};

const startSeeding = async () => {
someSeedFails = false;
console.log(
"\x1b[33m",
`
Expand All @@ -41,9 +50,15 @@ const startSeeding = async () => {
await checkAndExecuteSeed(seed);
}

console.log(`
\x1b[32mSeeding completed!\x1b[0m
`);
if (someSeedFails) {
console.log(
"\x1b[38;2;255;165;0m",
"Some seeds failed to execute.",
"\x1b[0m",
);
} else {
console.log("\x1b[32m", "All seeds executed successfully!", "\x1b[0m");
}
exit();
};

Expand Down
1 change: 1 addition & 0 deletions seeding/seeds/create-organizer-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ You can verify your email by clicking on the link below:\x1b[0m
`,
"\x1b[0m",
);
throw error;
} finally {
rl.close();
}
Expand Down
Loading