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

Method process

reconciliation.go:454–494  ·  view source on GitHub ↗

process handles individual transaction processing, applying the reconciliation logic and recording results. It also updates internal transaction metadata asynchronously when matches are found. Parameters: - ctx: The context controlling the request. - txn: The transaction to process. Returns: - error

(ctx context.Context, txn *model.Transaction)

Source from the content-addressed store, hash-verified

452// Returns:
453// - error: If processing or recording results fails.
454func (tp *transactionProcessor) process(ctx context.Context, txn *model.Transaction) error {
455 // Reconcile the batch of transactions and get matches and unmatched transactions.
456 batchMatches, batchUnmatched := tp.reconciler(ctx, []*model.Transaction{txn})
457
458 // Increment the counters for matched and unmatched transactions.
459 tp.matches += len(batchMatches)
460 tp.unmatched += len(batchUnmatched)
461
462 // If the reconciliation is not a dry run, record the matches and unmatched transactions.
463 if !tp.reconciliation.IsDryRun {
464 if len(batchMatches) > 0 {
465 // Record the matched transactions.
466 if err := tp.datasource.RecordMatches(ctx, tp.reconciliation.ReconciliationID, batchMatches); err != nil {
467 return err
468 }
469
470 // Asynchronously update the metadata for each matched internal transaction
471 go tp.updateMatchedTransactionsMetadata(context.Background(), batchMatches)
472 }
473
474 if len(batchUnmatched) > 0 {
475 // Record the unmatched transactions.
476 if err := tp.datasource.RecordUnmatched(ctx, tp.reconciliation.ReconciliationID, batchUnmatched); err != nil {
477 return err
478 }
479 }
480 }
481
482 // Update the progress with the last processed transaction ID and increment the processed count.
483 tp.progress.LastProcessedExternalTxnID = txn.TransactionID
484 tp.progress.ProcessedCount++
485
486 // Periodically save the reconciliation progress.
487 if tp.progress.ProcessedCount%tp.progressSaveCount == 0 {
488 if err := tp.datasource.SaveReconciliationProgress(ctx, tp.reconciliation.ReconciliationID, tp.progress); err != nil {
489 logrus.Errorf("Error saving reconciliation progress: %v", err)
490 }
491 }
492
493 return nil
494}
495
496// updateMatchedTransactionsMetadata updates the metadata for internal transactions that were matched.
497// This function adds reconciliation information to the internal transaction's metadata.

Callers 1

processTransactionsMethod · 0.80

Calls 4

RecordMatchesMethod · 0.65
RecordUnmatchedMethod · 0.65

Tested by

no test coverage detected