Skip to content

Commit

Permalink
Improve check links reliability (#3938)
Browse files Browse the repository at this point in the history
* feat: catch recorder error and skip priorityMap when happens

* feat: change le endpoint qu'on utilise sur le recorder

Note: Cet endpoint est plus facile à utilisé car il donne directement le
nombre d'évènements d'un type pour une aide donnée.
J'ai fait le choix de ne regarder que les trois derniers mois car :
- ça donne un priorité actuelle
- ça permet de limité le scope de la requête

* fix: remove pull_request trigger

This should be triggered by CI here : https://github.com/betagouv/aides-jeunes/blob/420263bfcb07a52dc0c8029b05577e1163a05e90/.github/workflows/ci.yml#L396
  • Loading branch information
baptou12 authored Sep 4, 2023
1 parent fd03119 commit 2a35063
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
1 change: 0 additions & 1 deletion .github/workflows/check-links-validity.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Check links validity
on:
workflow_dispatch:
pull_request:
schedule:
# https://crontab.guru/#30_8_*_*_*
- cron: "30 8 * * *"
Expand Down
48 changes: 24 additions & 24 deletions tools/check-links-validity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Mattermost from "../backend/lib/mattermost-bot/mattermost.js"
import axios from "axios"
import https from "https"
import Bluebird from "bluebird"
import * as Sentry from "@sentry/node"
import dayjs from "dayjs"

const DEFAULT_BRANCH_REF = "refs/heads/master"

Expand Down Expand Up @@ -84,36 +86,34 @@ function sleep(ms) {
}

async function getPriorityStats() {
const last3months: string = dayjs().subtract(3, "month").format("YYYY-MM-DD")
const stats = await axios
.get("https://aides-jeunes-stats-recorder.osc-fr1.scalingo.io/statistics")
.then((r) => r.data)
const statTotal = stats.map((v) => {
const p = v.events?.showDetails || {}
const totals = Object.keys(p)
return {
benefit: v.benefit,
count: totals.reduce((at, t) => {
const indexes = Object.keys(p[t])
return (
at +
indexes.reduce((ai, i) => {
return ai + p[t][i]
}, 0)
)
}, 0),
}
})
.get(
`https://aides-jeunes-stats-recorder.osc-fr1.scalingo.io/benefits?startAt=${last3months}`
)
.then((response) => response.data)

const statByBenefitId = statTotal.reduce((a, v) => {
a[v.benefit] = v.count
return a
}, {})
return stats.reduce((priorityMap, benefitStatsEvent) => {
const benefitId: string = benefitStatsEvent.id
const priority: number = benefitStatsEvent.events.showDetails

return statByBenefitId
if (priority) {
priorityMap[benefitId] = priority
}

return priorityMap
})
}

async function getBenefitData(noPriority: boolean) {
const priorityMap = noPriority ? {} : await getPriorityStats()
let priorityMap = {}
try {
priorityMap = noPriority ? {} : await getPriorityStats()
} catch (error) {
console.error(error)
Sentry.captureException(error)
console.warn("Unable to get priority stats, priorityMap is empty")
}

const data = Benefits.all.map((benefit) => {
const linkMap = ["link", "instructions", "form", "teleservice"]
Expand Down

0 comments on commit 2a35063

Please sign in to comment.