Budgets
A budget caps several actions: a sum or a number of lines, per scope and per period. It is a
reusable policy type: rule that
carries a budget instead of a require. It counts what the submits file with the tenant.
Writing a budget
policies:
depense-du-jour:
type: rule
budget: {sum: "$item.price", per: day, scope: identity, max: 60000} # per signed-in person
when: "$item.kind == 'dish'" # the lines it counts
reason: "plafond de 60 000 F CFA par jour atteint"
remboursements-du-mois:
budget: {sum: "$item.fields.montant", per: month, scope: station, max: 5000}
demandes-du-jour:
budget: {count: true, per: day, scope: room, max: 3}
| key | value |
|---|---|
sum | one reference: $item.price (the price of one unit) or $item.fields.<name>, a field of type number, integer, price or quantity. Each line counts this value × its quantity |
count: true | each line counts 1, whatever its quantity |
per | day, week (from Monday) or month (from the 1st) |
scope | identity, room or station (see The scope) |
max | a number greater than 0: the most the counter may reach in one period |
- A policy is a
requireor abudget, never both: write two policies. sumorcount: true, exactly one of the two.- The common attributes apply:
when,reason,mode,tags.effectisrefuse. - Periods start at 00:00 UTC: the day, the Monday of the week, the 1st of the month. A station declares no time zone.
Where to cite it
A budget is cited by its name, like any reusable policy:
station:
policies:
- {policy: depense-du-jour, at: submit} # every line of the station
skills:
- name: rembourser
select:
guards:
- {policy: remboursements-du-mois} # this skill's lines only
- In a skill's
select.guards, or inkinds.<k>.select.guards: it counts the lines of that skill (of that kind). - In
station.policies,at: selectorat: submit: it counts every line of the station. - The policy's
when, and the citation's, choose the lines it counts. - Refused at load:
- a budget written directly in a guard list (write it under
policies:and cite it); - a budget cited in
invoke.guards: a read files nothing; - a
sumthat is not one reference, for example$selection.totalor an expression (write$item.price: the budget multiplies it by each line's quantity); - a
sumon a field that is not a number, or on a field the skill does not declare; count: false,sumandcounttogether, or neither;- a
peror ascopeoutside the list, amaxof 0 or less; scope: identityon a station with no identity provider (station.identity.providers): no one can sign in there. Writescope: roomorscope: station.
- a budget written directly in a guard list (write it under
At the choice and at the submit
A budget is judged at phase 4 of the decision point: after the conditions (phase 3), before
the tenant's check.
- At the choice (where it is cited at
select): a line that alone would go beyond what is left in the period is refused at once, with the codebudget_exceeded. The tenant is not called. Nothing is counted: a choice files nothing. - At the submit (wherever it is cited): Core adds up the lines it covers that nothing has filed
yet. If the counter would go beyond
max, the submit is held: nothing is sent, and the sentence names the line that goes beyond. The journal names the rule by the policy's name, at phasebudget. - Allowed, the counter grows in the same transaction as the decision's journal entry: both, or neither.
- Two submits at the same time, when only one fits: only one passes. The other is refused with the same code.
- If the tenant answers that it filed nothing for a line (its call fails), its amount is given
back to the counter, in one transaction, with a
releaseentry in the journal. It names the policies only. A line the tenant filed at another total (total_mismatch) is given back too: it stays in the selection, and the retry that confirms it counts it once. - If what the tenant did is unknown (its call raises an error, or the selection cannot be read
again after the submit, or what is given back cannot be written): nothing is given back. What
was counted stays counted. The journal writes a
releaseentry, refused, with the codeoutcome_unknownand the policies by name, and the server writes it to its logs. The operator gives the amount back once they know the tenant filed nothing (see Giving back what was kept). - A line filed in part (some of its calls succeeded) is counted once: by the submit that started it. The retry that sends the rest does not count it again.
- A value that cannot be read (absent, not a number, negative) refuses the line with the code
budget_unreadable. It never counts as zero.
The scope: scope
scope | one counter for |
|---|---|
identity | the signed-in person, by their opaque id. Only a signed-in person is counted |
room | the room |
station | the whole station |
- A person who is not signed in and reaches an
identitybudget is held: they are asked to sign in, and nothing is counted. At the choice as at the submit, the outcome issign_in, the same as for a room owner's sign-in: the card or the selection tells the person in their own words, and the model is told to callsign_in, which it does not repeat to them. A held card offers Sign in right there (the same steps assign_in) and, once the person is signed in, makes the choice again itself, with what they answered in it. A choice asked of the model, Core reminds it of once the person is signed in, and it makes it again for them (without a form: their answers are never kept); a submit they make again themselves, the model shows them their selection again. - The counter never keeps a value of the person: an opaque id, the period and what was spent.
- A counter lives for its period only. When a submit spends on a budget, it deletes, in its transaction, that budget's counters whose period has ended.
Trying before applying
In mode: observe or mode: suggest, a budget refuses nothing and counts nothing. What it
would have refused is written to the journal, in observed, with the code budget_exceeded. In
suggest, its sentence is also given as advice to the person and the model (see
mode).
The sentences
With a reason, the person reads <line>: <reason>. Without one, Convoy's sentence:
- at the choice: "… would go beyond what is left of a limit of this station for this period — nothing was added";
- at the submit: "… would go beyond what is left of a limit of this station for this period — nothing was sent";
- a value that cannot be read: "…: what it counts toward a limit of this station cannot be read — it cannot be taken".
These sentences are rewritten with texts:
budget.select, budget.submit, budget.unreadable.
If the counter cannot be read
Core fails closed: the action is refused with the code journal_unavailable and the journal's
sentence ("this cannot be done right now: what is decided here cannot be recorded…"). Never a
lock, never a sign-in request.
Giving back what was kept
When the journal shows a release entry with the code outcome_unknown, what the submit counted
stays in the counter, since nobody knows whether the tenant filed it. Giving that amount back
yourself, once you are sure the tenant filed nothing, is not yet available to you: today Convoy
does it, and the give-back is written to the journal (release, actor operator). The same goes
for a uniqueness key.
In the registry
The registry lists each citation of a budget: origin reusable, source budget, phase 4. The
counter lives beside the journal: erasing a room does not touch it.
The target adds effect: needs-human (a person decides beyond the cap):
Budgets.