Repository navigation
Feature Request: Automatic Message Cleanup for GOWS Engine #1657
Description
Feature Request: Automatic Message Cleanup for GOWS Engine
Summary
Add automatic cleanup of old messages from the gows_messages table in PostgreSQL for all GOWS sessions, configurable via environment variables with cron-based scheduling.
Problem
When using the GOWS engine with PostgreSQL storage, the gows_messages table can grow indefinitely, consuming disk space and potentially impacting database performance. Currently, there's no built-in mechanism to automatically clean up old messages.
Proposed Solution
Implement an automatic cleanup system that:
- Periodically deletes messages older than a configurable retention period
- Processes all GOWS sessions automatically
- Uses cron-based scheduling for flexible execution times
- Provides detailed logging of cleanup operations
Technical Implementation
New Files
-
src/plus/engines/gows/services/GowsMessageCleanupService.ts- Service that handles message cleanup for individual sessions and all sessions
- Accesses PostgreSQL databases using
PsqlStore - Deletes messages where
timestamp < cutoffDate - Returns count of deleted messages
-
src/plus/engines/gows/services/GowsCleanupScheduler.ts- Scheduler service that uses
cron-parserto schedule cleanup jobs - Implements
OnModuleInitandOnApplicationShutdown - Calculates next execution time based on cron pattern
- Prevents overlapping executions
- Scheduler service that uses
-
src/plus/engines/gows/gows.module.ts- NestJS module that registers the cleanup services
- Validates environment variables using Joi
- Conditionally loads when PostgreSQL is configured
Module Integration
- Add
GowsModuletosrc/plus/app.module.plus.tswith conditional loading whenWHATSAPP_SESSIONS_POSTGRESQL_URLis defined - Export
SessionManagerandWhatsappConfigServicefromAppModulePlusfor dependency injection
Environment Variables
Number of days to keep messages (default: 90)
WAHA_GOWS_MESSAGE_RETENTION_DAYS=30
Cron pattern for cleanup schedule (default: "0 0 2 * * *" = daily at 2:00 AM)
Format: second minute hour day month day-of-week
WAHA_GOWS_CLEANUP_CRON="0 0 2 * * *"### Cron Pattern Examples
"0 0 2 * * *"- Every day at 2:00 AM (default)"0 30 3 * * *"- Every day at 3:30 AM"0 0 */6 * * *"- Every 6 hours"0 0 2 * * 0"- Every Sunday at 2:00 AM"0 0 2 1 * *"- First day of every month at 2:00 AM
Features
✅ Automatic cleanup for all GOWS sessions
✅ Configurable retention period (days)
✅ Flexible scheduling via cron patterns
✅ Detailed logging of cleanup operations
✅ Error handling per session (doesn't stop if one session fails)
✅ Prevents overlapping executions
✅ Graceful shutdown support
Dependencies
cron-parser(already in project dependencies)
Logging
The implementation provides detailed logs:
- Scheduler startup with configuration
- Next scheduled execution time
- Cleanup start/completion for each session
- Number of messages deleted per session
- Errors per session (non-blocking)
Activity
WilliamSantos96 commentedon Nov 24, 2025
up +
oasilap commentedon Nov 24, 2025
+1
StartecSistemas commentedon Nov 24, 2025
+1
mcabral2510 commentedon Nov 24, 2025
+1
snot1988 commentedon Nov 24, 2025
+1
devlikepro commentedon Nov 25, 2025
The endpoint to clean any tables would also help as the first thing
POST /api/{session}/store/clean/messages { keep: 30 days }and we could add a Cleanup App so you could configure it globally or per session on crontab schedule 🤔
bergpinheiro commentedon Nov 25, 2025
Yes, an endpoint is also a great option. Globally, it would also be a way to automate.
theeusmartins commentedon Dec 4, 2025
+1
favuka commentedon Dec 9, 2025
+1
oasilap commentedon Dec 9, 2025
+1
Felipewesley69 commentedon Dec 9, 2025
+1
vhiperdev commentedon Dec 9, 2025
+1
jayveloper commentedon Dec 9, 2025
+1
3 remaining items
phmzum commentedon Dec 18, 2025
+1
jayveloper commentedon Dec 24, 2025
+1
jevil25 commentedon Jan 2, 2026
+1
rafwell commentedon Jan 28, 2026
+1
higorrezend commentedon Jan 29, 2026
+1
GoCode-io commentedon Jan 29, 2026
+1
Elimeshi1 commentedon Jan 29, 2026
+1
brunojfnet commentedon Apr 3, 2026
+1
trojantm commentedon Apr 3, 2026
+1
brunocicom commentedon Apr 15, 2026
+1
olavomachadoshibata commentedon Apr 15, 2026
+1
simao-moreira commentedon Apr 24, 2026
+1
AnxHall commentedon May 8, 2026
+1
personalrad commentedon Aug 31, 2026
Hi. Is there any chance of this being implemented?
WenderGalan commentedon Oct 22, 2026
+1