-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Création d'un schéma dédié aux statistiques publiques (#2741)
* ✨ Ajout table statistique scalaire * ✨ Compute nombre total projet * ✨ Execution extraction donnée stats publiques * 🎨 Ajout script npm + bash * 🚚 Déplacer le package d'applications vers package dédié * 🗃️ Update database dev dump * 👷 Ajout d'un job verify_statistics * 💚 Fix verify statistives step * 💚 Fix missing env variable * 💚 Fix missing env variable * 🐛 Fix missing process.exit(0) * 🎨 Ajout d'un cron déclénché tout les jours à 6 AM * ✨ Monitor script on sentry --------- Co-authored-by: Sylvain Pontoreau <pontoreau.sylvain@gmail.com>
- Loading branch information
1 parent
78d18a3
commit a3f15b2
Showing
19 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# DATABASE | ||
EVENT_STORE_CONNECTION_STRING=postgres://potadmindb:localpwd@localhost:5432/potentiel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Command } from '@oclif/core'; | ||
import { z } from 'zod'; | ||
|
||
import { | ||
cleanStatistiquesPubliques, | ||
computeStatistiquesPubliques, | ||
} from '@potentiel-statistiques/statistiques-publiques'; | ||
|
||
const configSchema = z.object({ | ||
EVENT_STORE_CONNECTION_STRING: z.string(), | ||
}); | ||
|
||
export default class ExtraireStats extends Command { | ||
static override description = | ||
'Extrait les données des statistiques publiques (permet de tester la tâche planifiée dédiée)'; | ||
|
||
static override args = {}; | ||
|
||
static override flags = {}; | ||
|
||
public async init() { | ||
const { success } = configSchema.safeParse(process.env); | ||
console.info(`Env variables defined : ${success}`); | ||
} | ||
|
||
public async run(): Promise<void> { | ||
console.info('Lancement du script...'); | ||
|
||
console.info('Clean données statistiques publiques existantes'); | ||
await cleanStatistiquesPubliques(); | ||
|
||
console.info('Compute nouvelles données statistiques publiques'); | ||
await computeStatistiquesPubliques(); | ||
|
||
console.info('Fin du script ✨'); | ||
|
||
process.exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/applications/scheduled-tasks/extraire-données-statistiques-publiques.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#! /bin/bash -l | ||
|
||
|
||
if [ -z $EVENT_STORE_CONNECTION_STRING ] | ||
then | ||
echo "Connection is missing!" | ||
exit 1 | ||
fi | ||
|
||
if [ -z $SENTRY_CRONS ] | ||
then | ||
echo "A monitoring variable is missing !" | ||
fi | ||
|
||
SENTRY_URL=$(echo "$SENTRY_CRONS" | sed 's|<monitor_slug>|extraire-donnees-statistiques-publiques|') | ||
|
||
handle_error() { | ||
local message="Error on 'extraire-donnees-statistiques-publiques' script line $1" | ||
echo $message | ||
|
||
local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | ||
local hostname=$(hostname) | ||
|
||
curl "${MONITORING_URL}&status=error" | ||
|
||
exit 1 | ||
} | ||
|
||
trap 'handle_error $LINENO' ERR | ||
|
||
echo "Launching job [EXTRAIRE DONNÉES STATISTIQUES PUBLIQUES]" | ||
|
||
npm run start:extraire-données-statistiques-publiques -w @potentiel-applications/scheduled-tasks | ||
|
||
curl "${MONITORING_URL}&status=ok" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...ons/scheduled-tasks/src/statistiques-publiques/extraire-données-statistiques-publiques.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { | ||
cleanStatistiquesPubliques, | ||
computeStatistiquesPubliques, | ||
} from '@potentiel-statistiques/statistiques-publiques'; | ||
|
||
(async () => { | ||
await cleanStatistiquesPubliques(); | ||
await computeStatistiquesPubliques(); | ||
process.exit(0); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,9 @@ | |
}, | ||
{ | ||
"path": "../routes" | ||
}, | ||
{ | ||
"path": "../../statistiques/statistiques-publiques" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@potentiel-statistiques/statistiques-publiques", | ||
"version": "0.0.0", | ||
"description": "Statistics referential for the Potentiel public dashboard", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"@potentiel-libraries/pg-helpers": "*" | ||
}, | ||
"devDependencies": { | ||
"@potentiel-config/tsconfig": "*" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/statistiques/statistiques-publiques/sql/scalarStatistic.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
create table if not exists domain_public_statistic.scalar_statistic ( | ||
type varchar primary key not null, | ||
value decimal not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
create schema if not exists domain_public_statistic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { | ||
cleanNombreTotalProjet, | ||
computeNombreTotalProjet, | ||
} from './projet/nombreTotalProjet.statistic'; | ||
|
||
export const cleanStatistiquesPubliques = async () => { | ||
await cleanNombreTotalProjet(); | ||
}; | ||
|
||
export const computeStatistiquesPubliques = async () => { | ||
await computeNombreTotalProjet(); | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/statistiques/statistiques-publiques/src/projet/nombreTotalProjet.statistic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { executeQuery } from '@potentiel-libraries/pg-helpers'; | ||
|
||
export const cleanNombreTotalProjet = () => | ||
executeQuery(` | ||
delete | ||
from domain_public_statistic.scalar_statistic | ||
where type = 'nombreTotalProjet' | ||
`); | ||
|
||
export const computeNombreTotalProjet = () => | ||
executeQuery( | ||
` | ||
insert | ||
into domain_public_statistic.scalar_statistic | ||
values('nombreTotalProjet', ( | ||
select | ||
count(*) | ||
from | ||
domain_views.projection | ||
where key like 'candidature|%')) | ||
`, | ||
); |
12 changes: 12 additions & 0 deletions
12
packages/statistiques/statistiques-publiques/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "@potentiel-config/tsconfig/tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../../libraries/pg-helpers" | ||
} | ||
] | ||
} |