Skip to main content

headless_lms_credit_registration/use_cases/
legacy_mirror.rs

1//! The `legacy-mirror` phase: copying successful registrations to the legacy ledger.
2
3use headless_lms_models::library::credit_registration::legacy_mirror::{
4    LEGACY_MIRROR_LIMIT, mirror_successes_to_legacy_ledger,
5};
6use sqlx::PgPool;
7
8use crate::error::CreditRegistrationResult;
9use crate::workflow::Counts;
10use headless_lms_models::credit_registrations::RegistrationScope;
11
12pub(crate) async fn run(
13    pool: &PgPool,
14    scope: &RegistrationScope,
15) -> CreditRegistrationResult<Counts> {
16    let mut conn = pool.acquire().await?;
17    let mirrored = mirror_successes_to_legacy_ledger(&mut conn, scope, LEGACY_MIRROR_LIMIT).await?;
18    if mirrored > 0 {
19        debug!(
20            mirrored,
21            "Mirrored successful registrations to the legacy ledger"
22        );
23    }
24    Ok(Counts::processed(mirrored))
25}