Skip to content

moving database.retention.payment.days application property to an env#17

Open
Marshall71 wants to merge 2 commits into
mainfrom
feature/movingDataRetentionDayPropertyToEnv
Open

moving database.retention.payment.days application property to an env#17
Marshall71 wants to merge 2 commits into
mainfrom
feature/movingDataRetentionDayPropertyToEnv

Conversation

@Marshall71

Copy link
Copy Markdown
Collaborator

property test

Comment thread src/main/java/org/lagonette/hellos/service/PurgeDatabaseService.java Outdated
@Marshall71
Marshall71 force-pushed the feature/movingDataRetentionDayPropertyToEnv branch from 0c4bfa5 to b9d06e4 Compare April 16, 2022 12:02
@Marshall71
Marshall71 force-pushed the feature/movingDataRetentionDayPropertyToEnv branch from b9d06e4 to 3763620 Compare April 16, 2022 12:16
@Marshall71

Copy link
Copy Markdown
Collaborator Author

Je ne sais pas comment se passe ton job qui exécute les tests maven.
Mais si le job ne recopie pas le fichier ".env.dist" en le renommant ".env" et utilise un fichier ".env" il faut le compléter du coup en ajoutant la variable d'environnement:
DATABASE_RETENTION_PAYMENT_DAY=7

public void purgeDatabase() {
LOGGER.info("Begin of the database purge");

long nbOfDaysForPayments = Long.parseLong(dotenv.get("DATABASE_RETENTION_PAYMENT_DAY"));

@Marshall71 Marshall71 Apr 16, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jymaire parseLong génère une exception NumberFormatException si la valeur peut pas être convertie.
Comment veux tu qu'elle soit gérée ? Un try catch avec un log d'erreur en cas d'execption ?
Comment se passe le throws de l'exception si elle pope, ça kill l'application ?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est de la purge donc ça doit pas couper le process métier. Try catch et mail d'erreur (dans les logs c'est nécessaire mais pas suffisant)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ce qui pourrait être bien aussi, c'est de mettre une valeur par défaut (à 7 jours) si jamais la propriété n'est pas remplie (et un message de log en INFO pour prévenir, idéalement une seule fois au démarrage et pas chaque nuit)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

là je sèche parce que à part faire un compteur pour savoir si c'est la première fois je vois pas d'autre solution.
Je peux pas déclarer la variable nbOfDaysForPayments en static (variable de classe), car au moment ou j'initialiserai ma varialbe dans mon bloc static{} ma dotenv variable sera null (le constructeur n'aura pas encore été appelé) :'(

@jymaire jymaire Apr 16, 2022

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu as des events spring que tu peux attraper pour dire "execute moi ce boot de code une fois l'init terminée" (exemple ici : https://stackoverflow.com/questions/27405713/running-code-after-spring-boot-starts ) à voir si ça fonctionne comme tu veux :)
Edit : doc officielle avec les events dispo https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.spring-application.application-events-and-listeners

@jymaire

jymaire commented Apr 16, 2022

Copy link
Copy Markdown
Owner

pour le .env, c'est dans la partie CI que ça se passe https://github.com/jymaire/hellos/blob/main/.github/workflows/maven.yml#L24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants