M8-R03B: keep meter swap recompute in caller transaction
This commit is contained in:
@@ -665,7 +665,9 @@ def compute_closed_periods(session: Session) -> int:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def recompute_range(session: Session, start: datetime, end: datetime) -> int:
|
||||
def recompute_range(
|
||||
session: Session, start: datetime, end: datetime, *, commit: bool = True
|
||||
) -> int:
|
||||
"""Recompute (overwrite) all 15-minute periods in ``[start, end)``.
|
||||
|
||||
This is the *explicit opt-in* path for recovering from:
|
||||
@@ -686,8 +688,11 @@ def recompute_range(session: Session, start: datetime, end: datetime) -> int:
|
||||
Parameters
|
||||
----------
|
||||
session:
|
||||
Active SQLAlchemy session. The function commits after all periods
|
||||
have been processed.
|
||||
Active SQLAlchemy session.
|
||||
commit:
|
||||
When true (the default), commit after all periods have been processed.
|
||||
Callers composing this recompute with other writes may pass false and
|
||||
own the surrounding transaction themselves.
|
||||
start:
|
||||
Inclusive start datetime (floored to the nearest quarter-hour internally).
|
||||
end:
|
||||
@@ -724,7 +729,8 @@ def recompute_range(session: Session, start: datetime, end: datetime) -> int:
|
||||
)
|
||||
t0 += timedelta(minutes=_PERIOD_MINUTES)
|
||||
|
||||
session.commit()
|
||||
if commit:
|
||||
session.commit()
|
||||
logger.info(
|
||||
"recompute_range(%s, %s): wrote %d period(s).",
|
||||
start.isoformat(),
|
||||
|
||||
Reference in New Issue
Block a user