total_1ère
This commit is contained in:
36
modules/adhesion/majgs_webhook.js
Normal file
36
modules/adhesion/majgs_webhook.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/////////////////////////////////////////////////
|
||||
// LOGGING
|
||||
/////////////////////////////////////////////////
|
||||
const logger = require("../../public/js/app/logger_adhesion");
|
||||
const path = require("path");
|
||||
const cron = require('node-cron');
|
||||
const axios = require('axios');
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// FILE NAME
|
||||
////////////////////////////////////////////////////
|
||||
const filename = path.parse(__filename).base;
|
||||
|
||||
// URL du webhook
|
||||
//const WEBHOOK_URL = "http://localhost:8890/adhesion/maj_googlesheet_auto";
|
||||
const WEBHOOK_URL = "https://inscription.afpedagogiesuzuki.fr/adhesion/maj_googlesheet_auto";
|
||||
//const WEBHOOK_URL = process.env.adhesion_maj_gs_webhook_url; //cela ne fonctionne pas
|
||||
|
||||
// Fonction pour envoyer la requête POST
|
||||
const envoyerWebhook = async () => {
|
||||
try {
|
||||
const response = await axios.get(WEBHOOK_URL, {});
|
||||
logger.info("Webhook envoyé avec succès: " + response.status, { numsession:"webhook", label: filename});
|
||||
} catch (error) {
|
||||
logger.error("Erreur lors de l'envoi du webhook: " + error.message, { numsession:"webhook", label: filename});
|
||||
}
|
||||
};
|
||||
|
||||
// Définir la tâche cron : ici, elle s'exécute toutes les 2 minutes
|
||||
// cron.schedule('*/2 * * * *', () => {
|
||||
// Définir la tâche cron : ici, elle s'exécute à 3h du matin
|
||||
// cron.schedule('0 3 * * *', () => {
|
||||
cron.schedule('0 3 * * *', () => {
|
||||
logger.info("Envoi du webhook (modules/adhesion/majgs_webhook.js) à l'heure prévue", { numsession:"webhook", label: filename});
|
||||
envoyerWebhook();
|
||||
});
|
||||
Reference in New Issue
Block a user