SaveReconciliationProgress saves the progress of a reconciliation process to the database. If a record with the given reconciliation ID already exists, it updates the progress information. The function ensures that the reconciliation progress is stored and updated properly. Parameters: - ctx: Contex
(ctx context.Context, reconciliationID string, progress model.ReconciliationProgress)
| 675 | // Returns: |
| 676 | // - An error if the operation fails, wrapped in an APIError if needed. |
| 677 | func (d Datasource) SaveReconciliationProgress(ctx context.Context, reconciliationID string, progress model.ReconciliationProgress) error { |
| 678 | ctx, span := otel.Tracer("reconciliation.database").Start(ctx, "Saving reconciliation progress to db") |
| 679 | defer span.End() |
| 680 | |
| 681 | // Execute the query, with conflict handling to update if the record already exists |
| 682 | _, err := d.Conn.ExecContext(ctx, ` |
| 683 | INSERT INTO ledgerforge.reconciliation_progress (reconciliation_id, processed_count, last_processed_external_txn_id) |
| 684 | VALUES ($1, $2, $3) |
| 685 | ON CONFLICT (reconciliation_id) DO UPDATE |
| 686 | SET processed_count = $2, last_processed_external_txn_id = $3 |
| 687 | `, reconciliationID, progress.ProcessedCount, progress.LastProcessedExternalTxnID) |
| 688 | // Return an API error if the query fails |
| 689 | if err != nil { |
| 690 | return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to save reconciliation progress", err) |
| 691 | } |
| 692 | |
| 693 | return nil |
| 694 | } |
| 695 | |
| 696 | // LoadReconciliationProgress retrieves the progress of a reconciliation process from the database. If the reconciliation progress |
| 697 | // is not found, it returns an empty ReconciliationProgress object. |