Skip to main content

cmd/taisce/rebuildstaleness.go

cmd/taisce · 93 lines · 2 declarations · source

Declarations

func withStaleness

func withStaleness(ctx context.Context, pool *pgxpool.Pool, schema pg.Schema, scope string, result any) any

withStaleness returns the rebuild's own result with what it left behind added beside it.

Why the result's own fields stay where they are

An operator scripts against this output. Nesting the result under a key to make room for a new one would move every field somebody already reads, for the convenience of the field being added — the wrong way round. So the result is marshalled as it always was and two keys are added next to its own: `stale`, present only when something is, and `what_to_do`, which says the next step rather than restating the problem.

Why staleness is read and never stored

These are consequences of the state the database is in now. The subject pass writes reports back continuously, so a number recorded at the end of a rebuild would be wrong by the time anybody looked at it.

A failure to read it is not a failure of the rebuild, which has already committed: the operator is told what happened and simply is not told what is stale. Turning a successful rebuild into an error because a count could not be taken would be the reporting breaking the thing it reports on.

source

func plural

func plural(n int64) string

plural says how far behind in words rather than in a template with a number in it, because an operator reads this at two in the morning.

source