MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / processWorker

Function processWorker

internal/files/files.go:319–370  ·  view source on GitHub ↗
(ctx context.Context, uploadID, source string, rowChan <-chan []string, columnMap map[string]int, store StoreFunc, totalCount *int64, countMu *sync.Mutex, errChan chan<- error)

Source from the content-addressed store, hash-verified

317}
318
319func processWorker(ctx context.Context, uploadID, source string, rowChan <-chan []string, columnMap map[string]int, store StoreFunc, totalCount *int64, countMu *sync.Mutex, errChan chan<- error) {
320 batch := make([]model.ExternalTransaction, 0, DefaultBatchSize)
321 processCount := 0
322
323 for record := range rowChan {
324 select {
325 case <-ctx.Done():
326 return
327 default:
328 }
329
330 externalTxn, err := parseExternalTransaction(record, columnMap, source)
331 if err != nil {
332 errChan <- err
333 continue
334 }
335
336 batch = append(batch, externalTxn)
337
338 // Process batch when full
339 if len(batch) >= DefaultBatchSize {
340 if err := storeBatch(ctx, uploadID, batch, store); err != nil {
341 errChan <- err
342 } else {
343 countMu.Lock()
344 *totalCount += int64(len(batch))
345 countMu.Unlock()
346 }
347 batch = batch[:0] // Reset batch
348 }
349
350 processCount++
351 if processCount%ContextCheckInterval == 0 {
352 select {
353 case <-ctx.Done():
354 return
355 default:
356 }
357 }
358 }
359
360 // Process remaining items in batch
361 if len(batch) > 0 {
362 if err := storeBatch(ctx, uploadID, batch, store); err != nil {
363 errChan <- err
364 } else {
365 countMu.Lock()
366 *totalCount += int64(len(batch))
367 countMu.Unlock()
368 }
369 }
370}
371
372func storeBatch(ctx context.Context, uploadID string, batch []model.ExternalTransaction, store StoreFunc) error {
373 for _, txn := range batch {

Callers 1

processCSVRowsParallelFunction · 0.85

Calls 4

parseExternalTransactionFunction · 0.85
storeBatchFunction · 0.85
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected