MCPcopy
hub / github.com/destel/rill / updateUserTimestampWorker

Function updateUserTimestampWorker

example_test.go:145–159  ·  view source on GitHub ↗

This is a background worker that sends queued updates to the database in batches. For simplicity, there are no retries, error handling and synchronization

()

Source from the content-addressed store, hash-verified

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
145func 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.

Callers 1

Example_batchingRealTimeFunction · 0.85

Calls 3

FromChanFunction · 0.92
BatchFunction · 0.92
ForEachFunction · 0.92

Tested by

no test coverage detected