From 1e37cdc270a641473da975c1084294233e0b39c1 Mon Sep 17 00:00:00 2001 From: antoineludeau <52679050+antoineludeau@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:35:25 +0200 Subject: [PATCH 1/3] Added a check not to compose an assemblage that already has ban ids --- lib/compose/index.cjs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/compose/index.cjs b/lib/compose/index.cjs index 33e75c5e..8833a47c 100644 --- a/lib/compose/index.cjs +++ b/lib/compose/index.cjs @@ -85,6 +85,13 @@ async function composeCommune(codeCommune, ignoreIdConfig) { const isBAL = Boolean(currentRevision) + // Si la commune est déjà composée avec un identifiant BAN : + // On ne la recompose plus pour ne pas écraser les identifiants BAN existants + if (!isBAL && !compositionOptions.force && commune?.banId) { + console.log(`${codeCommune} | commune 'assemblage' avec identifiant BAN déjà présent => composition ignorée`) + return false + } + // La bloc suivant garantit qu'il n'y a pas de retour en arrière. // Ne sera plus nécessaire quand l'API de dépôt contiendra 100% des BAL contenues dans la BAN if (!isBAL && commune?.typeComposition === 'bal') { From ae69d5f4c140a397c3960207bb395e12adb5428e Mon Sep 17 00:00:00 2001 From: antoineludeau <52679050+antoineludeau@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:33:49 +0200 Subject: [PATCH 2/3] Modified compose-all-force script to ask-compose-all with force as an arg --- .../{compose-all-force.cjs => ask-compose-all.cjs} | 12 ++++++++++-- package.json | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) rename lib/compose/{compose-all-force.cjs => ask-compose-all.cjs} (61%) diff --git a/lib/compose/compose-all-force.cjs b/lib/compose/ask-compose-all.cjs similarity index 61% rename from lib/compose/compose-all-force.cjs rename to lib/compose/ask-compose-all.cjs index a38410ca..a52ea369 100644 --- a/lib/compose/compose-all-force.cjs +++ b/lib/compose/ask-compose-all.cjs @@ -1,23 +1,31 @@ #!/usr/bin/env node /* eslint no-await-in-loop: off */ require('dotenv').config() +const argv = require('minimist')(process.argv.slice(2), {string: '_'}) const mongo = require('../util/mongo.cjs') const {askComposition} = require('../models/commune.cjs') const {getCommunes} = require('../util/cog.cjs') async function main() { + const force = argv.force || false + if (force) { + console.info('option "force" activée') + } + await mongo.connect() const codesCommunesBAN = await mongo.db.collection('communes').distinct('codeCommune') const currentCodes = new Set(codesCommunesBAN) const communes = getCommunes().filter(c => currentCodes.has(c.code)) + console.log(`Communes à composer: ${communes.length}`) for (const commune of communes) { - await askComposition(commune.code, {force: true}) + await askComposition(commune.code, {force}) } - console.log('Composition forcée demandée') + console.log('Composition France entière demandée') + console.log('Faire un `yarn compose` pour lancer la composition') await mongo.disconnect() process.exit(0) } diff --git a/package.json b/package.json index 0766d5e0..080abccb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "import:ftth": "node lib/import/cli.cjs ftth", "dist": "node lib/distribute/cli.cjs", "compose": "node lib/compose/cli.cjs", - "composeAllForce": "node lib/compose/compose-all-force.cjs", + "askComposeAll": "node lib/compose/ask-compose-all.cjs", "lint": "xo", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest", "worker": "node worker.js", From 2cee1dfd4fa2d8fbf4c68acc96b5e2308d13a406 Mon Sep 17 00:00:00 2001 From: antoineludeau <52679050+antoineludeau@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:28:25 +0200 Subject: [PATCH 3/3] Added a force option to the compose cli --- lib/compose/cli.cjs | 3 ++- lib/compose/worker.cjs | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/compose/cli.cjs b/lib/compose/cli.cjs index 2d1e2517..44fcf092 100755 --- a/lib/compose/cli.cjs +++ b/lib/compose/cli.cjs @@ -12,10 +12,11 @@ async function main() { // Check if --ignoreIdConfig flag is provided const ignoreIdConfig = argv.ignoreIdConfig || false + const force = argv.force || false await runInParallel( require.resolve('./worker.cjs'), - communes.map(codeCommune => ({codeCommune, ignoreIdConfig})), + communes.map(codeCommune => ({codeCommune, force, ignoreIdConfig})), {maxWorkerMemory: 3072, maxRetries: 5} ) diff --git a/lib/compose/worker.cjs b/lib/compose/worker.cjs index 99e74310..d8fe1731 100644 --- a/lib/compose/worker.cjs +++ b/lib/compose/worker.cjs @@ -4,10 +4,17 @@ const composeCommune = require('./index.cjs') async function main(options) { await mongo.connect() - const {codeCommune, ignoreIdConfig} = options + const {codeCommune, force, ignoreIdConfig} = options console.time(`commune ${codeCommune}`) + if (force) { + await mongo.db.collection('communes').updateOne( + {codeCommune}, + {$set: {compositionOptions: {force: true}}} + ) + } + await composeCommune(codeCommune, ignoreIdConfig) await finishComposition(codeCommune)