Custom Tasks
Create custom scheduled operations.
Create custom scheduled tasks for operations beyond built-in health checks and backups.
Custom Task Types
| Type | Description | Use Case |
|---|---|---|
custom | Run shell commands | Maintenance scripts |
container-update | Update Docker images | Keep containers current |
Create Container Update Task
Automatically update project container images:
Via API
curl -X POST https://supascale.example.com/api/v1/tasks \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"name": "Weekly Container Updates",
"enabled": true,
"type": "container-update",
"projectId": "production",
"cronExpression": "0 4 * * 0",
"timezone": "UTC",
"containerUpdateConfig": {
"pullImages": true,
"restartAfterUpdate": true
}
}'
Configuration Options
| Option | Description | Default |
|---|---|---|
pullImages | Pull latest images | true |
restartAfterUpdate | Restart project after update | true |
Create Custom Script Task
Run custom maintenance scripts:
curl -X POST https://supascale.example.com/api/v1/tasks \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"name": "Database Vacuum",
"enabled": true,
"type": "custom",
"projectId": "production",
"cronExpression": "0 5 * * 0",
"timezone": "UTC",
"customConfig": {
"command": "docker exec production-db psql -U postgres -c \"VACUUM ANALYZE;\""
}
}'
Common Custom Tasks
Database Maintenance
{
"name": "Weekly VACUUM",
"type": "custom",
"cronExpression": "0 5 * * 0",
"customConfig": {
"command": "docker exec ${PROJECT_ID}-db psql -U postgres -c 'VACUUM ANALYZE;'"
}
}
Log Rotation
{
"name": "Rotate Logs",
"type": "custom",
"cronExpression": "0 0 * * *",
"customConfig": {
"command": "find /var/log/supascale -name '*.log' -mtime +7 -delete"
}
}
Cleanup Temp Files
{
"name": "Cleanup Temp",
"type": "custom",
"cronExpression": "0 3 * * *",
"customConfig": {
"command": "find /tmp -name 'supascale-*' -mtime +1 -delete"
}
}
Disk Space Check
{
"name": "Disk Space Alert",
"type": "custom",
"cronExpression": "0 */6 * * *",
"customConfig": {
"command": "df -h / | awk 'NR==2 {if ($5+0 > 80) exit 1}'"
}
}
Task Execution Environment
Custom commands run with:
- Working directory: Supascale installation directory
- User: Supascale process user
- Environment: Access to environment variables
- Timeout: Default 5 minutes
Available Variables
| Variable | Description |
|---|---|
PROJECT_ID | Target project ID |
PROJECT_DIR | Project directory path |
BACKUP_DIR | Backup directory path |
Viewing Task Results
Via API
curl https://supascale.example.com/api/v1/tasks/task-123 \ -H "X-API-Key: your-api-key"
Response:
{
"id": "task-123",
"name": "Database Vacuum",
"lastRun": "2026-01-19T05:00:00Z",
"lastStatus": "success",
"history": [
{
"executedAt": "2026-01-19T05:00:00Z",
"status": "success",
"duration": 15000,
"output": "VACUUM\n"
}
]
}
Run Task Immediately
Test custom task:
curl -X POST https://supascale.example.com/api/v1/tasks/task-123/run \ -H "X-API-Key: your-api-key"
Response:
{
"success": true,
"execution": {
"status": "success",
"duration": 15000,
"output": "VACUUM\n"
}
}
Error Handling
Task Failure
Tasks fail if:
- Command returns non-zero exit code
- Execution times out
- Command not found
View Errors
Check task history for failure details:
{
"history": [
{
"executedAt": "2026-01-19T05:00:00Z",
"status": "failed",
"error": "Command timed out after 300000ms"
}
]
}
Best Practices
Security
- Avoid sensitive data in commands
- Use environment variables for secrets
- Limit permissions of Supascale user
- Audit task commands regularly
Reliability
- Test commands manually first
- Set appropriate timeouts
- Handle errors gracefully
- Log important output
Maintenance
- Document tasks and their purpose
- Review periodically for relevance
- Monitor execution history
- Clean up unused tasks
Troubleshooting
Command Not Found
- Use absolute paths
- Verify command exists
- Check PATH in environment
Permission Denied
- Check file/directory permissions
- Verify Supascale user has access
- Consider using sudo (if configured)
Timeout
- Increase timeout setting
- Optimize command performance
- Split into smaller tasks
- Run during low-activity periods