|
1 | 1 | # Async Operations |
2 | 2 |
|
3 | | -The `redisctl` CLI provides comprehensive support for asynchronous operations across both Redis Cloud and Redis Enterprise APIs. All create, update, and delete operations support the `--wait` flag family for tracking long-running operations. |
| 3 | +Many Redis Cloud and Enterprise operations are asynchronous - they return immediately with a task ID while the work happens in the background. redisctl handles this automatically. |
4 | 4 |
|
5 | | -## Overview |
| 5 | +## The --wait Flag |
6 | 6 |
|
7 | | -Many Redis Cloud API operations are asynchronous, returning immediately with a task ID while the operation continues in the background. The `--wait` flags allow you to: |
8 | | - |
9 | | -- Wait for operations to complete before returning |
10 | | -- Track progress with visual indicators |
11 | | -- Set custom timeouts for long operations |
12 | | -- Configure polling intervals |
13 | | - |
14 | | -## Wait Flag Options |
15 | | - |
16 | | -| Flag | Description | Default | |
17 | | -|------|-------------|---------| |
18 | | -| `--wait` | Wait for operation to complete | Timeout: 600s | |
19 | | -| `--wait-timeout <seconds>` | Custom timeout duration | 600 | |
20 | | -| `--wait-interval <seconds>` | Polling interval | 10 | |
21 | | - |
22 | | -## Basic Usage |
| 7 | +Use `--wait` to block until the operation completes: |
23 | 8 |
|
24 | 9 | ```bash |
25 | | -# Create database and wait for completion |
26 | | -redisctl cloud database create --subscription-id 12345 \ |
27 | | - --data @database.json --wait |
28 | | - |
29 | | -# With custom timeout for large operations |
30 | | -redisctl cloud database create --subscription-id 12345 \ |
31 | | - --data @large-db.json --wait --wait-timeout 1800 |
32 | | - |
33 | | -# With faster polling for quick operations |
34 | | -redisctl cloud database update --subscription-id 12345 \ |
35 | | - --database-id 67890 --data @updates.json \ |
36 | | - --wait --wait-interval 2 |
37 | | -``` |
38 | | - |
39 | | -## Progress Tracking |
40 | | - |
41 | | -When using the `--wait` flag, redisctl provides real-time progress tracking: |
| 10 | +# Returns immediately with task ID |
| 11 | +redisctl cloud database create --subscription-id 123 --data '{...}' |
42 | 12 |
|
| 13 | +# Waits for completion, returns final result |
| 14 | +redisctl cloud database create --subscription-id 123 --data '{...}' --wait |
43 | 15 | ``` |
44 | | -Creating database... |
45 | | -⠋ Waiting for task 12345 to complete... (10s) |
46 | | -⠙ Status: processing (20s) |
47 | | -⠹ Status: processing (30s) |
48 | | -✓ Database creation completed successfully |
49 | | -``` |
50 | | - |
51 | | -## Supported Operations |
52 | 16 |
|
53 | | -Async operations are supported across all major command categories: |
| 17 | +## Polling Options |
54 | 18 |
|
55 | | -- [Database Operations](./database-operations.md) - Create, update, delete, import, backup, migrate |
56 | | -- [Subscription Management](./subscription-management.md) - Regular and fixed subscriptions |
57 | | -- [Network Connectivity](./network-connectivity.md) - VPC Peering, PSC, Transit Gateway |
58 | | -- [ACL Management](./acl-management.md) - Rules, roles, and users |
59 | | -- [User & Account Management](./user-management.md) - Users and provider accounts |
| 19 | +Control how redisctl polls for completion: |
60 | 20 |
|
61 | | -## Error Handling |
| 21 | +```bash |
| 22 | +redisctl cloud subscription create \ |
| 23 | + --data '{...}' \ |
| 24 | + --wait \ |
| 25 | + --poll-interval 10 \ # Check every 10 seconds (default: 5) |
| 26 | + --max-wait 600 # Timeout after 10 minutes (default: 300) |
| 27 | +``` |
62 | 28 |
|
63 | | -### Timeout Behavior |
| 29 | +## Task Management |
64 | 30 |
|
65 | | -If an operation exceeds the timeout: |
66 | | -- The CLI exits with an error |
67 | | -- The task continues running in the background |
68 | | -- You can check status using the task ID |
| 31 | +### Check Task Status |
69 | 32 |
|
70 | 33 | ```bash |
71 | | -# Operation times out |
72 | | -Error: Operation timed out after 600 seconds. Task 12345 is still running. |
| 34 | +# Cloud |
| 35 | +redisctl cloud task get <task-id> |
73 | 36 |
|
74 | | -# Check task status manually |
75 | | -redisctl cloud task get 12345 |
| 37 | +# Enterprise |
| 38 | +redisctl enterprise action get <action-id> |
76 | 39 | ``` |
77 | 40 |
|
78 | | -### Recovery Options |
| 41 | +### List Recent Tasks |
79 | 42 |
|
80 | 43 | ```bash |
81 | | -# Retry with longer timeout |
82 | | -redisctl cloud database create --data @database.json \ |
83 | | - --wait --wait-timeout 1800 |
| 44 | +# Cloud - list all tasks |
| 45 | +redisctl cloud task list |
84 | 46 |
|
85 | | -# Check task status without waiting |
86 | | -redisctl cloud task list --status pending |
| 47 | +# Enterprise - list actions |
| 48 | +redisctl enterprise action list |
87 | 49 | ``` |
88 | 50 |
|
89 | | -## Best Practices |
| 51 | +## Common Async Operations |
90 | 52 |
|
91 | | -### Choosing Timeouts |
| 53 | +### Redis Cloud |
92 | 54 |
|
93 | | -- **Small operations**: Default 600s is usually sufficient |
94 | | -- **Large databases**: Increase to 1800s (30 min) or more |
95 | | -- **Bulk operations**: Consider 3600s (1 hour) for very large datasets |
96 | | -- **Network operations**: May need longer timeouts in some regions |
| 55 | +- `subscription create/delete` |
| 56 | +- `database create/update/delete` |
| 57 | +- `vpc-peering create/delete` |
| 58 | +- `cloud-account create/delete` |
97 | 59 |
|
98 | | -### Polling Intervals |
| 60 | +### Redis Enterprise |
99 | 61 |
|
100 | | -- **Default (10s)**: Good balance for most operations |
101 | | -- **Fast operations (2-5s)**: For operations you expect to complete quickly |
102 | | -- **Long operations (30-60s)**: Reduce API calls for very long operations |
| 62 | +- `database create/update/delete` |
| 63 | +- `cluster join/remove-node` |
| 64 | +- `module upload` |
103 | 65 |
|
104 | | -### Automation |
| 66 | +## Error Handling |
105 | 67 |
|
106 | | -The `--wait` flags are designed for automation: |
| 68 | +When `--wait` is used and an operation fails: |
107 | 69 |
|
108 | 70 | ```bash |
109 | | -#!/bin/bash |
110 | | -# CI/CD pipeline example |
111 | | -set -e # Exit on error |
112 | | - |
113 | | -# Create infrastructure |
114 | | -redisctl cloud subscription create --data @prod-sub.json \ |
115 | | - --wait --wait-timeout 1800 |
| 71 | +$ redisctl cloud database create --data '{...}' --wait |
| 72 | +Error: Task failed: Invalid memory configuration |
| 73 | + |
| 74 | +# Check task details |
| 75 | +$ redisctl cloud task get abc-123 |
| 76 | +{ |
| 77 | + "taskId": "abc-123", |
| 78 | + "status": "failed", |
| 79 | + "error": "Invalid memory configuration" |
| 80 | +} |
| 81 | +``` |
116 | 82 |
|
117 | | -SUB_ID=$(redisctl cloud subscription list -q "[0].id" -o json) |
| 83 | +## Scripting Patterns |
118 | 84 |
|
119 | | -redisctl cloud database create --subscription-id $SUB_ID \ |
120 | | - --data @prod-db.json --wait --wait-timeout 900 |
| 85 | +### Wait and Extract Result |
121 | 86 |
|
122 | | -echo "Infrastructure ready!" |
| 87 | +```bash |
| 88 | +# Create and get the new database ID |
| 89 | +DB_ID=$(redisctl cloud database create \ |
| 90 | + --subscription-id 123 \ |
| 91 | + --data '{"name": "mydb"}' \ |
| 92 | + --wait \ |
| 93 | + -q 'databaseId') |
| 94 | + |
| 95 | +echo "Created database: $DB_ID" |
123 | 96 | ``` |
124 | 97 |
|
125 | | -## Parallel Operations |
| 98 | +### Fire and Forget |
| 99 | + |
| 100 | +```bash |
| 101 | +# Start multiple operations in parallel |
| 102 | +redisctl cloud database delete 123 456 & |
| 103 | +redisctl cloud database delete 123 789 & |
| 104 | +wait |
| 105 | +``` |
126 | 106 |
|
127 | | -You can run multiple async operations in parallel: |
| 107 | +### Custom Polling |
128 | 108 |
|
129 | 109 | ```bash |
130 | | -#!/bin/bash |
131 | | -# Create multiple databases in parallel |
132 | | -for i in {1..5}; do |
133 | | - redisctl cloud database create --subscription-id 12345 \ |
134 | | - --data @db-$i.json --wait & |
| 110 | +# Start operation |
| 111 | +TASK_ID=$(redisctl cloud database create --data '{...}' -q 'taskId') |
| 112 | + |
| 113 | +# Custom polling loop |
| 114 | +while true; do |
| 115 | + STATUS=$(redisctl cloud task get $TASK_ID -q 'status') |
| 116 | + echo "Status: $STATUS" |
| 117 | + |
| 118 | + if [ "$STATUS" = "completed" ] || [ "$STATUS" = "failed" ]; then |
| 119 | + break |
| 120 | + fi |
| 121 | + |
| 122 | + sleep 10 |
135 | 123 | done |
136 | | - |
137 | | -# Wait for all background jobs |
138 | | -wait |
139 | | -echo "All databases created!" |
140 | 124 | ``` |
141 | 125 |
|
142 | | -## Implementation Details |
| 126 | +## Timeouts |
| 127 | + |
| 128 | +If an operation exceeds `--max-wait`: |
143 | 129 |
|
144 | | -All async operations use the centralized `handle_async_response` function which: |
145 | | -- Extracts task IDs from API responses |
146 | | -- Polls for task completion |
147 | | -- Provides consistent progress indicators |
148 | | -- Handles timeouts and errors uniformly |
| 130 | +```bash |
| 131 | +$ redisctl cloud subscription create --data '{...}' --wait --max-wait 60 |
| 132 | +Error: Operation timed out after 60 seconds. Task ID: abc-123 |
| 133 | + |
| 134 | +# Check manually |
| 135 | +$ redisctl cloud task get abc-123 |
| 136 | +``` |
149 | 137 |
|
150 | | -The system automatically detects task IDs from various response formats: |
151 | | -- `taskId` field in response |
152 | | -- `links` array with task references |
153 | | -- Nested task objects |
| 138 | +The operation continues in the background - only the CLI stops waiting. |
0 commit comments