diff --git a/cron.json b/cron.json index d1699c53c5..a9735d26de 100644 --- a/cron.json +++ b/cron.json @@ -4,6 +4,10 @@ "command": "0 8 * * 0 ./packages/applications/scheduled-tasks/mettre-à-jour-gestionnaire-réseau.sh", "size": "M" }, + { + "command": "0 8 * * 1-5 ./packages/applications/scheduled-tasks/attribuer-grd.sh", + "size": "M" + }, { "command": "0 1 * * * ./packages/applications/scheduled-tasks/relancer-abandon-sans-preuve.sh", "size": "M" diff --git a/packages/applications/scheduled-tasks/attribuer-grd.sh b/packages/applications/scheduled-tasks/attribuer-grd.sh new file mode 100644 index 0000000000..edfc670784 --- /dev/null +++ b/packages/applications/scheduled-tasks/attribuer-grd.sh @@ -0,0 +1,19 @@ +#! /bin/bash -l + +if [ -z $EVENT_STORE_CONNECTION_STRING ] +then + echo "Connection is missing!" + exit 1 +fi + +if [ -z $ORE_ENDPOINT ] +then + echo "Ore endpoint is missing!" + exit 1 +fi + +echo "Launching job [ATTRIBUER GRD]" + +npm run start:start:attribuer-grd -w @potentiel-applications/scheduled-tasks + +exit 0 diff --git a/packages/applications/scheduled-tasks/package.json b/packages/applications/scheduled-tasks/package.json index 05b179c6dd..83b5598e51 100644 --- a/packages/applications/scheduled-tasks/package.json +++ b/packages/applications/scheduled-tasks/package.json @@ -6,7 +6,6 @@ "scripts": { "build": "tsc", "start:attribuer-grd": "node ./dist/raccordement/attribuer-gestionnaire-réseau", - "start:maj-grd-des-projets-avec-raccordement": "node ./dist/raccordement/maj-gestionnaire-réseau-des-projets-avec-raccordement", "start:relancer-abandon-sans-preuve": "node ./dist/abandon/relancer-abandon-sans-preuve", "start:déplacer-fichiers-vers-bucket-secnum": "node ./dist/déplacer-fichiers-vers-bucket-secnum", "start:créer-backup": "node ./dist/backup/créer-backup", diff --git "a/packages/applications/scheduled-tasks/src/raccordement/attribuer-gestionnaire-r\303\251seau.ts" "b/packages/applications/scheduled-tasks/src/raccordement/attribuer-gestionnaire-r\303\251seau.ts" index da08a4023c..706d8e4657 100644 --- "a/packages/applications/scheduled-tasks/src/raccordement/attribuer-gestionnaire-r\303\251seau.ts" +++ "b/packages/applications/scheduled-tasks/src/raccordement/attribuer-gestionnaire-r\303\251seau.ts" @@ -87,11 +87,8 @@ registerRéseauQueries({ } if (projetsSansGestionnaire.length) { - const pourcentageProjetsNonTrouvés = Math.round( - (projetsSansGestionnaireTrouvés / projetsSansGestionnaire.length) * 100, - ); getLogger().info( - `Sur ${projetsSansGestionnaire.length} projets classés sans raccordement, nous n'avons pas pu attribuer de GRD à ${pourcentageProjetsNonTrouvés} % d'entre eux`, + `Sur ${projetsSansGestionnaire.length} projets classés sans raccordement, nous n'avons pas pu attribuer de GRD à ${projetsSansGestionnaireTrouvés} d'entre eux`, ); } diff --git "a/packages/applications/scheduled-tasks/src/raccordement/maj-gestionnaire-r\303\251seau-des-projets-avec-raccordement.ts" "b/packages/applications/scheduled-tasks/src/raccordement/maj-gestionnaire-r\303\251seau-des-projets-avec-raccordement.ts" deleted file mode 100644 index 0c1e82197d..0000000000 --- "a/packages/applications/scheduled-tasks/src/raccordement/maj-gestionnaire-r\303\251seau-des-projets-avec-raccordement.ts" +++ /dev/null @@ -1,122 +0,0 @@ -import { mediator } from 'mediateur'; - -import { getLogger } from '@potentiel-libraries/monitoring'; -import { - Raccordement, - registerRéseauQueries, - registerRéseauUseCases, -} from '@potentiel-domain/reseau'; -import { listerProjetForOreAdapter } from '@potentiel-infrastructure/domain-adapters'; -import { loadAggregate } from '@potentiel-infrastructure/pg-event-sourcing'; -import { - countProjection, - findProjection, - listProjection, -} from '@potentiel-infrastructure/pg-projections'; -import { récupérerGRDParVille } from '@potentiel-infrastructure/ore-client'; -import { Option } from '@potentiel-libraries/monads'; - -registerRéseauUseCases({ - loadAggregate, -}); - -registerRéseauQueries({ - list: listProjection, - find: findProjection, - count: countProjection, -}); - -(async () => { - getLogger().info('Lancement du script...'); - - const args = process.argv.slice(2); - const offset = args[0] ? Number(args[0]) : 0; - const limit = args[1] ? Number(args[1]) : 5000; - - try { - const projetsClassé = await listerProjetForOreAdapter({ offset, limit }); - const projetsClasséIdentifiants = projetsClassé.map((p) => p.identifiantProjet); - - const raccordements = await mediator.send({ - type: 'Réseau.Raccordement.Query.ListerRaccordement', - data: {}, - }); - - const raccordementsDeProjetsClassés = raccordements.items.filter((raccordement) => - projetsClasséIdentifiants.includes(raccordement.identifiantProjet.formatter()), - ); - - getLogger().info(`${raccordementsDeProjetsClassés.length} raccordements à vérifier`); - - let nombreDeRaccordementsMisAJour = 0; - let nombreDeRaccordementsQuiNontPasPuEtreVerifies = 0; - let nombreDeRaccordementsDéjàAttribuésAuBonGRD = 0; - - for (const raccordement of raccordementsDeProjetsClassés) { - const identifiantProjet = raccordement.identifiantProjet.formatter(); - const identifiantActuelGestionnaireRéseau = - raccordement.identifiantGestionnaireRéseau.formatter(); - - const relatedProjet = projetsClassé.find( - (projet) => projet.identifiantProjet === identifiantProjet, - ); - - // ce cas est déjà vérifié ci dessus mais typescript est restrictif - if (!relatedProjet) { - getLogger().warn(`Il n'y a pas de projet classé lié à ce raccordement`); - continue; - } - - const nouveauGestionnaireRéseau = await récupérerGRDParVille({ - codePostal: relatedProjet.localité.codePostal, - commune: relatedProjet.localité.commune, - }); - - if (Option.isNone(nouveauGestionnaireRéseau)) { - nombreDeRaccordementsQuiNontPasPuEtreVerifies++; - continue; - } - - if (nouveauGestionnaireRéseau.codeEIC === identifiantActuelGestionnaireRéseau) { - getLogger().info( - `😎 Le gestionnaire réseau actuellement relié au projet ${identifiantProjet} est le même que celui de ORE`, - ); - nombreDeRaccordementsDéjàAttribuésAuBonGRD++; - continue; - } - - try { - await mediator.send({ - type: 'Réseau.Raccordement.UseCase.ModifierGestionnaireRéseauRaccordement', - data: { - identifiantProjetValue: identifiantProjet, - identifiantGestionnaireRéseauValue: nouveauGestionnaireRéseau.codeEIC, - }, - }); - - nombreDeRaccordementsMisAJour++; - - getLogger().info( - `✅ Gestionnaire ${nouveauGestionnaireRéseau.raisonSociale} attribué au projet ${identifiantProjet}`, - ); - } catch (error) { - getLogger().error(error as Error); - continue; - } - } - - getLogger().info( - `💪${nombreDeRaccordementsDéjàAttribuésAuBonGRD} raccordements étaient déjà attribués au bon gestionnaire`, - ); - getLogger().info( - `Sur ${ - raccordementsDeProjetsClassés.length - nombreDeRaccordementsDéjàAttribuésAuBonGRD - } raccordements à mettre à jour, nous avons mis à jour ${nombreDeRaccordementsMisAJour} d'entre eux et ${nombreDeRaccordementsQuiNontPasPuEtreVerifies} n'ont pas pu être vérifiés`, - ); - getLogger().info('Fin du script ✨'); - - process.exit(0); - } catch (error) { - getLogger().error(error as Error); - } -})();