Finalize a period
This guide closes one billing month. The run's records become immutable, the period stops taking new ones, and what arrives afterwards is booked by a correction. Where the gate sits in the month's life is in billing period lifecycle and corrections.
Before you start
- The engine database reachable from the machine you run the CLI on, and its connection string.
- A completed run of the month, and its id.
tally-engineat the version the deployment runs, with its subcommands on the engine CLI page.- The engine settings page, which names
TALLY_ENGINE_DB_URL, the one variable this guide sets.
Close the month
Point the engine at its own database.
finalizereads and writes that database alone, because the records it turns immutable are already stored:shexport TALLY_ENGINE_DB_URL='postgres://tally:password@db.internal:5432/tally_engine?sslmode=require'Name the month and the run that bills it:
shtally-engine finalize --period 2026-07 --run <run id>textrun <run id> finalized, period 2026-07 closedMetering the month again is refused, and the error opens on
the billing period is finalized. It comes before a run row exists. The command below runs under the environment run a period sets:shtally-engine run --period 2026-07textthe billing period is finalizedTALLY_ENGINE_AUTO_FINALIZElets the hourly tick take this step for a completed run instead. It isfalseby default, so the close stays a command somebody runs.
Check the result
List the periods. The month reads
finalizedand names the run that closed it and when:shtally-engine periods listtext2026-07 finalized finalized_run=<run id> finalized_at=<instant> 2026-08 openA period is
open,graceorfinalized, and only a finalized one carries the twofinalized_values. The2026-08line beside it is the month the hourly tick opened; a database with no period at all answersno billing periods.Events that reached the reporting database after the finalized run read the month are found by detect-late and booked by correct. The finalized run itself stays as it is.