Decisions
Decisions
A decision is a small program that chooses what a screen shows. It belongs to one campaign. For a screen, at a moment, it picks one variant (a row of the campaign’s table) from the variants that are built and approved. Mestra runs it for each screen that shows the campaign.
A campaign without a live decision is answered by its table, as before. See Dynamic variants. A decision can look at more than the table’s conditions can: the screen’s place, the items that belong to that place, your data feeds and the time.
Nothing a decision does can show something that isn’t approved. It can only choose from variants that are built and passed. If a decision can’t give an answer, the screen shows the default variant.
Who can do what
Anyone in the organisation can read decisions, versions, logs and replays. Owners write, test, make live and take down. A person acting as Mestra support can read but not change.
The Decisions page
Decisions lists your decisions. Each line shows the decision’s name, its campaign, which version is live (“Version 3 is live” or “No version is live”), and “Running well” or “This decision failed on its last run: …”.
An owner sees New decision. Select a decision to open it.
Write a decision
-
Select New decision.
-
Key. Lower-case letters, digits,
-or_, starting with a letter, up to 63 characters. It can’t be changed. These keys are reserved:new,test,from-tableandlog. -
Name. 1 to 80 characters.
-
Campaign. Choose one. A decision stays with its campaign. To decide for another campaign, make a new decision.
-
Write the source in the editor. It starts with:
Python def decide(ctx):# Choose a row with show(row_id, "why"). ctx.default is the default row.return show(ctx.default, "the default")A gutter shows line numbers. If the source can’t be read, the line is marked and a message says “Line 3: …”.
-
Select Save.
To start from what the campaign’s table does now, select Start from this campaign’s table. Mestra writes the table as a decision that gives the same answer as the table. Edit it from there. If the table is too long to edit as a decision, Mestra says “This table is too large to edit as a decision. It still runs as a table.”
Saving makes a version
Each save of changed source makes a new version, numbered from 1. Saving the same source again changes nothing, and Mestra says “No change: this is still version 2.” Saving does not make a version live. A new save says “Saved as version 3.”
A source can be at most 64 KiB. If it can’t be read, nothing is saved and the line is marked. If the key is bad, the page says “Use lower-case letters, digits, - or _, starting with a letter.” If the name is empty or too long, it says “Give the decision a name of 1 to 80 characters.” If the campaign isn’t one of yours, it says “Choose a campaign that’s in your account.”
To try it, make it live, take it down or read what it did, see Test, go live and read the log.
When a decision can’t answer
A decision never leaves a screen with nothing when it can help it. It falls back to the campaign’s default variant when:
| Reason | What it means |
|---|---|
| it doesn’t compile | The source can’t be read. |
| it stopped with an error | The source raised an error while running, such as turning a word into a number. |
| it took too many steps | It ran past 100,000 steps. |
| it used too much memory | It used more than 16 MiB. |
| it didn’t choose a row | It returned something other than show(...). |
| it chose a row that isn’t built and passed | The row isn’t in the table, is switched off, or isn’t ready. |
The default must itself be ready to show. If it isn’t, the table answers instead. The decisions page says “This decision failed on its last run: it took too many steps. Screens are showing the default.” The home page lists such a decision under “needs a look” as “falling back to the table” or “has no answer to show”, with how many screens are affected.
If Mestra can’t run decisions for a moment, or can’t read what a decision needs, a screen keeps what it showed last. Nothing is logged as the decision’s failure.
Decisions and bookings that swap artwork
A campaign can have bookings that swap artwork on a connected screen system. Those bookings keep following the table, not the decision. When this applies, the decision’s page says “This campaign also has bookings that swap artwork on the screen system. Those still follow the table.”
Limits
| Limit | Value |
|---|---|
| Source | 64 KiB |
| Steps in one run | 100,000 |
| Memory in one run | 16 MiB |
| What a decision can read for one screen | 256 KiB |
| A reason | 200 characters, then cut |
See the decision language for what a decision can use.