mongo-keepalive (Rust)
Prevent MongoDB Atlas free-tier clusters from becoming inactive by periodically sending a ping command.
MongoDB Atlas pauses free-tier (M0) clusters after 60 days of inactivity. This library keeps your cluster alive by running db.adminCommand({ ping: 1 }) on a configurable interval (default: every 12 hours).
Installation
Add to your Cargo.toml:
[]
= "1.0.0"
= { = "1", = ["rt-multi-thread", "macros"] }
Usage
use start_keep_alive;
async
Features
- ⚡ Async/await - Built on Tokio for efficient concurrency
- 🔄 Automatic retry - 3 attempts with 5-second delays
- 📝 Logging - Uses the
logcrate for observability - 🛡️ Error handling - Comprehensive error types
- ♻️ Graceful shutdown - Clean stop mechanism via handle
How It Works
- Connects to MongoDB using the official async driver
- Spawns a background task that pings every interval
- Retries failed pings automatically
- Logs all operations for monitoring
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
uri |
&str |
- | MongoDB connection string (required) |
interval |
&str |
"12h" |
Ping interval (e.g. "6h", "30m") |
Interval Format
"30m"→ 30 minutes"6h"→ 6 hours"12h"→ 12 hours (default)
Links
License
This project is licensed under the MIT License.