This is a background worker that sends queued updates to the database in batches. For simplicity, there are no retries, error handling and synchronization
()
| 143 | // This is a background worker that sends queued updates to the database in batches. |
| 144 | // For simplicity, there are no retries, error handling and synchronization |
| 145 | func updateUserTimestampWorker() { |
| 146 | // convert channel of userIDsStream into a stream |
| 147 | ids := rill.FromChan(userIDsToUpdate, nil) |
| 148 | |
| 149 | // Group IDs into batches of 5 for bulk processing |
| 150 | // In case of sparse updates, we want to send them to the database no later than 100ms after they were queued. |
| 151 | idBatches := rill.Batch(ids, 5, 100*time.Millisecond) |
| 152 | |
| 153 | // Send updates to the database |
| 154 | // Concurrency = 1 (this controls max number of concurrent updates) |
| 155 | _ = rill.ForEach(idBatches, 1, func(batch []int) error { |
| 156 | fmt.Printf("Executed: UPDATE users SET last_active_at = NOW() WHERE id IN (%v)\n", batch) |
| 157 | return nil |
| 158 | }) |
| 159 | } |
| 160 | |
| 161 | // This example demonstrates how to find the first file containing a specific string among 1000 large files |
| 162 | // hosted online. |
no test coverage detected