The BrickSwitch app now includes automatic schedule execution. You have several options for running schedules automatically:
The Streamlit app includes a built-in background scheduler that runs within the app:
- Start the scheduler: Click "
▶️ Start Auto Scheduler" in the web interface - Monitor status: The scheduler status is shown as "🟢 Running" or "🔴 Stopped"
- View logs: Click "📜 View Logs" to see execution history
Pros: Easy to use, integrated with the web interface Cons: Only runs while the Streamlit app is running
Use the standalone scheduler.py script for more robust operation:
# Run once
python scheduler.py
# Run continuously (daemon mode)
python scheduler.py --daemon
# Run with custom interval (every 5 minutes)
python scheduler.py --daemon --interval 300Add to your crontab (crontab -e):
# Run every minute
* * * * * cd /path/to/brickswitch && python scheduler.py
# Run every 5 minutes
*/5 * * * * cd /path/to/brickswitch && python scheduler.py
# Run every hour
0 * * * * cd /path/to/brickswitch && python scheduler.py-
Edit the service file:
sudo cp brickswitch-scheduler.service /etc/systemd/system/ sudo nano /etc/systemd/system/brickswitch-scheduler.service
-
Update the paths in the service file:
- Replace
/path/to/brickswitchwith your actual directory - Replace
/path/to/your/python/env/binwith your Python environment - Replace
your-usernamewith your actual username
- Replace
-
Enable and start the service:
sudo systemctl daemon-reload sudo systemctl enable brickswitch-scheduler sudo systemctl start brickswitch-scheduler -
Check status:
sudo systemctl status brickswitch-scheduler sudo journalctl -u brickswitch-scheduler -f
Create a Dockerfile for containerized deployment:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "scheduler.py", "--daemon"]- Execution logs:
schedule_execution.log - Contains: Timestamps, actions taken, errors
# View real-time logs
tail -f schedule_execution.log
# View recent logs
tail -n 50 schedule_execution.log
# Search for errors
grep -i error schedule_execution.log- File:
app_schedules.json - Format: JSON with app schedules
- Backup: Recommended to backup this file regularly
{
"my-app": {
"start_time": "09:00:00",
"stop_time": "18:00:00",
"weekend_off": true,
"additional_off_days": ["Friday"],
"custom_off_dates": ["2024-12-25", "2024-01-01"],
"enabled": true,
"created_at": "2024-01-15T10:30:00"
}
}The scheduler respects the same Databricks authentication as the main app:
DATABRICKS_HOSTDATABRICKS_TOKEN- Or use
~/.databrickscfg
- Authentication errors: Ensure Databricks credentials are properly configured
- Permission errors: Check file permissions and user access
- Network issues: Verify connectivity to Databricks workspace
# Run with verbose output
python scheduler.py --daemon 2>&1 | tee scheduler.log# Check if scheduler is working
python -c "
import json
import os
from datetime import datetime
# Check if log file exists and has recent entries
log_file = 'schedule_execution.log'
if os.path.exists(log_file):
with open(log_file, 'r') as f:
lines = f.readlines()
if lines:
print(f'Last log entry: {lines[-1].strip()}')
else:
print('Log file is empty')
else:
print('No log file found')
"- Backup schedules: Regularly backup
app_schedules.json - Monitor logs: Set up log rotation and monitoring
- Test schedules: Use manual execution to test before enabling auto-scheduler
- Redundancy: Consider running multiple scheduler instances with coordination
- Alerting: Set up alerts for scheduler failures
- Credentials: Store Databricks credentials securely
- File permissions: Restrict access to schedule and log files
- Network: Ensure secure connection to Databricks
- Audit: Regularly review schedule execution logs