Background Workers
Background services and workers in TMA Cloud.
Overview
TMA Cloud uses background workers for asynchronous processing and maintenance tasks.
Workers
Audit Worker
Purpose: Process audit events asynchronously
Command:
npm run worker
Configuration:
AUDIT_WORKER_CONCURRENCY- Concurrent events processedAUDIT_JOB_TTL_SECONDS- Job TTL
Important: Must run in production. Audit events queued but not written until processed.
Cleanup Services
Trash Cleanup
- Automatic deletion after 15 days
- Runs every 24 hours
- Permanent file deletion from storage
Orphan Cleanup
- Removes files without database records
- Periodic scanning
- Disk space recovery
Share Link Cleanup
- Deletes expired share links (
expires_at < NOW()) - Sets
shared = falseon files that no longer have an active share link - Runs at startup and every 7 days
- Invalidates related caches after cleanup
Running Workers
Production
# Terminal 1 - Main application
npm start
# Terminal 2 - Audit worker (required)
npm run worker
Docker
Workers run as separate containers:
docker compose up -d
# Starts app, worker, and redis
Monitoring Workers
Monitoring Audit Worker
- Check logs for processing status
- Monitor queue size
- Verify events being written
Monitoring Cleanup Services
- Check logs for cleanup operations
- Monitor disk space
- Verify cleanup schedules
Best Practices
- Always run audit worker in production
- Monitor worker health
- Check logs regularly
- Verify background tasks completing
Related Topics
- Audit Logs - Audit system
- Monitoring - System monitoring
- Logging - Application logging