From c3ae9cfa2f5d0ddee28874f4561e54e60000806d Mon Sep 17 00:00:00 2001 From: Camillo bucciarelli Date: Sat, 13 Jul 2024 13:06:57 +0200 Subject: [PATCH] INFRA28 --- seeding/check-seeding-status.js | 1 + seeding/package.json | 3 ++- seeding/run-seeding.js | 23 +++++++++++++++++++---- seeding/seeds/create-organizer-account.js | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/seeding/check-seeding-status.js b/seeding/check-seeding-status.js index a685bcfc..7ae25096 100644 --- a/seeding/check-seeding-status.js +++ b/seeding/check-seeding-status.js @@ -15,6 +15,7 @@ const checkSeedingStatus = async () => { exit(1); } } + exit(0); }; checkSeedingStatus(); diff --git a/seeding/package.json b/seeding/package.json index 7c4ff333..016af0c6 100644 --- a/seeding/package.json +++ b/seeding/package.json @@ -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" diff --git a/seeding/run-seeding.js b/seeding/run-seeding.js index feaa6f23..6db08c7d 100644 --- a/seeding/run-seeding.js +++ b/seeding/run-seeding.js @@ -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(); @@ -23,6 +31,7 @@ const checkAndExecuteSeed = async (seed) => { }; const startSeeding = async () => { + someSeedFails = false; console.log( "\x1b[33m", ` @@ -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(); }; diff --git a/seeding/seeds/create-organizer-account.js b/seeding/seeds/create-organizer-account.js index 7c0a0fc1..fc8fa534 100644 --- a/seeding/seeds/create-organizer-account.js +++ b/seeding/seeds/create-organizer-account.js @@ -55,6 +55,7 @@ You can verify your email by clicking on the link below:\x1b[0m `, "\x1b[0m", ); + throw error; } finally { rl.close(); }