1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
# Task Management Example
This example shows how to monitor and manage Meilisearch tasks.
## What it does
1. Create an index (generates a task)
2. Add documents (generates a task)
3. Update settings (generates a task)
4. Wait for tasks to complete
5. Get individual task details
6. List all tasks with filters
7. Filter tasks by type (document operations only)
## Task information shown
For each task you see:
- Task ID and type
- Status (enqueued, processing, succeeded, failed)
- Start and finish times
- Duration
- Error details if it failed
## Configuration
```bash
export MEILI_HOST="http://localhost:7700"
export MEILI_API_KEY="your-admin-api-key"
```
Note: You need an admin API key (not a search key) to manage tasks.
## Run it
```bash
go run ./examples/manage_tasks
```
```
Testing connection to Meilisearch...
✅ Connected to Meilisearch (status: available)
1. Creating index for task demonstration...
✅ Task #1 (Index Creation) completed with status: succeeded
Duration: 2ms
2. Adding documents to generate tasks...
✅ Task #2 (Document Addition) completed with status: succeeded
Duration: 15ms
3. Updating settings...
✅ Task #3 (Settings Update) completed with status: succeeded
Duration: 8ms
4. Retrieving individual task information...
Task #2:
- Type: documentAdditionOrUpdate
- Status: succeeded
- Started At: 2024-01-15T10:30:45Z
- Finished At: 2024-01-15T10:30:45Z
- Duration: 15ms
5. Listing all tasks...
Found 3 tasks total
6. Filtering tasks by type...
Found 1 document-related tasks
Task management example completed successfully! 🎉
## Best Practices Shown
- Always wait for critical tasks to complete
- Use appropriate timeouts for task waiting
- Filter tasks efficiently for monitoring
- Handle task errors gracefully
- Monitor task performance with statistics
|