Maintenance & Cron Jobs
Plugged.in includes automated maintenance tasks to keep your installation running smoothly. These tasks handle cleanup operations, scheduled emails, and database maintenance.Overview
The platform uses a dual-approach for automated tasks:In-Process Scheduler
Automatic - Runs within the application✅ No external configuration needed✅ Works in all environments⚠️ Stops when app restarts
External Cron Jobs
Recommended for Production✅ Runs independently of app✅ Better for serverless/cloud⚠️ Requires configuration
Automated Tasks
1. OAuth PKCE State Cleanup
Purpose: Removes expired OAuth PKCE states to prevent database bloat and ensure security. Frequency: Every 10 minutes Methods:- In-Process (Automatic)
- External Cron (Recommended)
The cleanup runs automatically when the application starts and continues every 10 minutes.No configuration needed - it just works!
The in-process scheduler skips in test environments to avoid interference with tests.
2. Scheduled Email Processing
Purpose: Sends scheduled welcome emails and follow-up messages to new users. Frequency: Every hour Endpoint:POST /api/emails/process-scheduled
Requirements:
CLOUD_DEPLOY=truein productionCRON_SECRETfor authentication
3. OAuth Session Cleanup
Purpose: Removes expired OAuth sessions from legacy mcp-remote servers. Frequency: Every hour (built-in) Method: Automatic in-process onlyEnvironment Variables
Required for Cron Jobs
.env
Monitoring & Logs
Check Cleanup Status
Response Format
Application Logs
Check your application logs for cleanup activity:Docker
Systemd
Troubleshooting
Cleanup Not Running
In-process cleanup not working
In-process cleanup not working
Symptoms: No cleanup logs in application outputSolutions:
- Verify you’re not in test environment (
NODE_ENV !== 'test') - Check application logs for initialization message
- Restart the application to trigger startup cleanup
- Ensure
lib/oauth/pkce-cleanup.tsis being imported somewhere
External cron returning 401
External cron returning 401
Symptoms:
Unauthorized error from APISolutions:- Verify
CRON_SECRETis set in environment - Check Authorization header format:
Bearer YOUR_SECRET - Ensure secret matches in both .env and cron configuration
External cron not triggering
External cron not triggering
Symptoms: No API calls in logsSolutions:
- Verify cron job configuration (timing, URL)
- Check cron service logs (GitHub Actions, Vercel, etc.)
- Test endpoint manually with curl
- Ensure endpoint is accessible from cron service
Cleanup running but states not deleted
Cleanup running but states not deleted
Symptoms:
deletedCount: 0 in all responsesSolutions:- Check database connection
- Verify PKCE states exist:
SELECT * FROM oauth_pkce_states - Check expiration times: States expire after 10 minutes
- Review application logs for errors
Best Practices
Production Deployment
1
Use External Cron
Configure external cron jobs for critical tasks (PKCE cleanup, scheduled emails) to ensure they run even during app restarts or deployments.
2
Set CRON_SECRET
Generate a strong random secret and configure it in your environment:
3
Monitor Failures
Set up monitoring/alerting for cron job failures:
- GitHub Actions: Email notifications
- Vercel: Error tracking in dashboard
- Custom: Log aggregation (Sentry, LogDNA, etc.)
4
Keep In-Process as Backup
The in-process scheduler acts as a failsafe if external cron fails. Don’t disable it.
Development Setup
For local development, the automatic in-process scheduler is sufficient:- No cron configuration needed
- Cleanup runs automatically on startup
- Continues every 10 minutes while app is running
- Use GET endpoints for manual testing
Testing Cleanup Manually
Summary
TL;DR:✅ In-process cleanup works automatically - no config needed✅ For production, add external cron jobs for reliability✅ Set
CRON_SECRET to secure your cron endpoints✅ Both methods work together for redundancyRecommended Production Setup:
- Enable
CLOUD_DEPLOY=true - Set strong
CRON_SECRET - Configure external cron for OAuth cleanup (every 10 min)
- Configure external cron for scheduled emails (every hour)
- Monitor cron job execution and errors
- Keep in-process scheduler as failsafe

