Skip to main content

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}
keyvalue
sumone 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: trueeach line counts 1, whatever its quantity
perday, week (from Monday) or month (from the 1st)
scopeidentity, room or station (see The scope)
maxa number greater than 0: the most the counter may reach in one period
  • A policy is a require or a budget, never both: write two policies.
  • sum or count: true, exactly one of the two.
  • The common attributes apply: when, reason, mode, tags. effect is refuse.
  • 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 in kinds.<k>.select.guards: it counts the lines of that skill (of that kind).
  • In station.policies, at: select or at: 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 sum that is not one reference, for example $selection.total or an expression (write $item.price: the budget multiplies it by each line's quantity);
    • a sum on a field that is not a number, or on a field the skill does not declare;
    • count: false, sum and count together, or neither;
    • a per or a scope outside the list, a max of 0 or less;
    • scope: identity on a station with no identity provider (station.identity.providers): no one can sign in there. Write scope: room or scope: station.

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 code budget_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 phase budget.
  • 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 release entry 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 release entry, refused, with the code outcome_unknown and 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​

scopeone counter for
identitythe signed-in person, by their opaque id. Only a signed-in person is counted
roomthe room
stationthe whole station
  • A person who is not signed in and reaches an identity budget is held: they are asked to sign in, and nothing is counted. At the choice as at the submit, the outcome is sign_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 call sign_in, which it does not repeat to them. A held card offers Sign in right there (the same steps as sign_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.