mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-22 14:38:19 +02:00
Resolve production issues by implementing a PostgreSQL backup module and fixing ESM compatibility
Replace `node-cron` with native `setTimeout` in `backupService.ts` to address dynamic require errors in ESM, and introduce a PostgreSQL backup module with administrative interface and automated scheduling. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7c468936-2a88-4686-ac0a-84921a45222d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/7c468936-2a88-4686-ac0a-84921a45222d/fhCGgjv
This commit is contained in:
1 parent
fbeb36c04a
commit
1c126fb77a
3 files changed
+233
-12
No files matched your search
+197
@@ -0,0 +1,197 @@
|
|||||||
|
|
||||||
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
^
|
||||||
|
|
||||||
|
Error: Dynamic require of "events" is not supported
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:11:9
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:4502:32
|
||||||
|
|
||||||
|
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||||
|
|
||||||
|
Node.js v20.19.4
|
||||||
|
|
||||||
|
🔗 Database initialization: {
|
||||||
|
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
|
||||||
|
isProduction: true,
|
||||||
|
|
||||||
|
hasDbUrl: true,
|
||||||
|
|
||||||
|
dbHost: 'logiflow-db'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
🐳 PRODUCTION: Using standard PostgreSQL
|
||||||
|
|
||||||
|
✅ PostgreSQL connection test successful
|
||||||
|
|
||||||
|
🔗 Database initialization: {
|
||||||
|
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
|
||||||
|
isProduction: true,
|
||||||
|
|
||||||
|
hasDbUrl: true,
|
||||||
|
|
||||||
|
dbHost: 'logiflow-db:5432'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
✅ Using DatabaseStorage (production PostgreSQL)
|
||||||
|
|
||||||
|
file:///app/dist/index.js:11
|
||||||
|
|
||||||
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
^
|
||||||
|
|
||||||
|
Error: Dynamic require of "events" is not supported
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:11:9
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:4502:32
|
||||||
|
|
||||||
|
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||||
|
|
||||||
|
Node.js v20.19.4
|
||||||
|
|
||||||
|
🔗 Database initialization: {
|
||||||
|
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
|
||||||
|
isProduction: true,
|
||||||
|
|
||||||
|
hasDbUrl: true,
|
||||||
|
|
||||||
|
dbHost: 'logiflow-db'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
🐳 PRODUCTION: Using standard PostgreSQL
|
||||||
|
|
||||||
|
✅ PostgreSQL connection test successful
|
||||||
|
|
||||||
|
🔗 Database initialization: {
|
||||||
|
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
|
||||||
|
isProduction: true,
|
||||||
|
|
||||||
|
hasDbUrl: true,
|
||||||
|
|
||||||
|
dbHost: 'logiflow-db:5432'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
✅ Using DatabaseStorage (production PostgreSQL)
|
||||||
|
|
||||||
|
file:///app/dist/index.js:11
|
||||||
|
|
||||||
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
^
|
||||||
|
|
||||||
|
Error: Dynamic require of "events" is not supported
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:11:9
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:4502:32
|
||||||
|
|
||||||
|
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||||
|
|
||||||
|
Node.js v20.19.4
|
||||||
|
|
||||||
|
🔗 Database initialization: {
|
||||||
|
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
|
||||||
|
isProduction: true,
|
||||||
|
|
||||||
|
hasDbUrl: true,
|
||||||
|
|
||||||
|
dbHost: 'logiflow-db'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
🐳 PRODUCTION: Using standard PostgreSQL
|
||||||
|
|
||||||
|
✅ PostgreSQL connection test successful
|
||||||
|
|
||||||
|
🔗 Database initialization: {
|
||||||
|
|
||||||
|
NODE_ENV: 'production',
|
||||||
|
|
||||||
|
isProduction: true,
|
||||||
|
|
||||||
|
hasDbUrl: true,
|
||||||
|
|
||||||
|
dbHost: 'logiflow-db:5432'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
✅ Using DatabaseStorage (production PostgreSQL)
|
||||||
|
|
||||||
|
file:///app/dist/index.js:11
|
||||||
|
|
||||||
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
^
|
||||||
|
|
||||||
|
Error: Dynamic require of "events" is not supported
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:11:9
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/tasks/inline-scheduled-task.js (file:///app/dist/index.js:3561:36)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at node_modules/node-cron/dist/esm/node-cron.js (file:///app/dist/index.js:4042:35)
|
||||||
|
|
||||||
|
at __require2 (file:///app/dist/index.js:17:50)
|
||||||
|
|
||||||
|
at file:///app/dist/index.js:4502:32
|
||||||
|
|
||||||
|
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
|
||||||
|
|
||||||
|
Node.js v20.19.4
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +19,15 @@ La plateforme fournit une gestion robuste des flux de travail de livraison avec
|
|||||||
|
|
||||||
## Recent Changes
|
## Recent Changes
|
||||||
|
|
||||||
|
### 2025-08-13 - Module de sauvegarde PostgreSQL implémenté + correction ESM
|
||||||
|
✅ **Module de sauvegarde PostgreSQL complet** :
|
||||||
|
- **Interface BackupManager** : Affichage des sauvegardes avec détails (taille, tables, statut)
|
||||||
|
- **Fonctions** : Création manuelle, suppression, téléchargement de sauvegardes SQL
|
||||||
|
- **Automatisation** : Sauvegardes programmées à 2h du matin avec timer natif
|
||||||
|
- **Base de données** : Table `DATABASE_BACKUPS` avec suivi complet des sauvegardes
|
||||||
|
- **Navigation** : Ajouté dans la sidebar administration pour les admins
|
||||||
|
- **Compatibilité ESM** : Remplacement de `node-cron` par `setTimeout` natif pour résoudre l'erreur production
|
||||||
|
|
||||||
### 2025-08-13 - Optimisation performance production + correction calendrier
|
### 2025-08-13 - Optimisation performance production + correction calendrier
|
||||||
✅ **Résolution latence production** :
|
✅ **Résolution latence production** :
|
||||||
- **Problème** : Console saturée par centaines de logs "API Response" causant latence
|
- **Problème** : Console saturée par centaines de logs "API Response" causant latence
|
||||||
|
|||||||
+27
-12
@@ -2,7 +2,6 @@ import { exec } from 'child_process';
|
|||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import cron from 'node-cron';
|
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { eq, desc } from "drizzle-orm";
|
import { eq, desc } from "drizzle-orm";
|
||||||
import { db } from "./db";
|
import { db } from "./db";
|
||||||
@@ -187,19 +186,35 @@ export class BackupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private scheduleAutomaticBackup(): void {
|
private scheduleAutomaticBackup(): void {
|
||||||
// Schedule backup every night at 2:00 AM
|
// Use native setTimeout instead of node-cron for ESM compatibility
|
||||||
cron.schedule('0 2 * * *', async () => {
|
const scheduleNextBackup = () => {
|
||||||
try {
|
const now = new Date();
|
||||||
console.log('🌙 Starting scheduled automatic backup...');
|
const next2AM = new Date(now);
|
||||||
await this.createBackup('automatic');
|
next2AM.setHours(2, 0, 0, 0);
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Scheduled backup failed:', error);
|
// If it's already past 2 AM today, schedule for tomorrow
|
||||||
|
if (now.getHours() >= 2) {
|
||||||
|
next2AM.setDate(next2AM.getDate() + 1);
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
timezone: 'Europe/Paris'
|
const msUntilBackup = next2AM.getTime() - now.getTime();
|
||||||
});
|
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
console.log('🔄 Starting automatic backup...');
|
||||||
|
await this.createBackup('automatic', 'system');
|
||||||
|
console.log('✅ Automatic backup completed');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Automatic backup failed:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Schedule the next backup (24 hours later)
|
||||||
|
scheduleNextBackup();
|
||||||
|
}, msUntilBackup);
|
||||||
|
};
|
||||||
|
|
||||||
console.log('⏰ Automatic backup scheduled for 2:00 AM daily');
|
scheduleNextBackup();
|
||||||
|
console.log('⏰ Automatic backup scheduled for 2:00 AM daily (native timer)');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user