Summary#
How often a function is called is a fact about its CALLER, and the source does not hold it. A host that polls every
five seconds calls its poll 17,280 times a day; nothing in the poll's own code says so, and every per-call cost rule
judges it as if it ran once. Mark it, and osy lint knows:
entity Host {
[MaxLength(40)] string Name = "";
long Seen;
security { allow read when IsAuthenticated; }
}
class PollAnswer { public long Version; public bool Unchanged; }
[Polled(EverySeconds = 5)]
PollAnswer Poll(Host host, long known) {
if (host.Seen == known) { return new PollAnswer { Version = known, Unchanged = true }; }
return new PollAnswer { Version = host.Seen };
}Signature#
[Polled(EverySeconds = <whole seconds, 1 to 86400>)]
<ReturnType> <Name>(<parameters>) { … }Description#
What it changes#
Nothing about how the function runs, is called, is secured or is deployed. It is a statement for the linter: the
function is judged by A polled function pays only for what changed on what EVERY call pays when nothing changed — a read the same for every
caller, a read per row in a loop, a write on every path, housekeeping for everybody, a runas — and each finding
says how many calls a day the interval means for each caller.
Where it goes#
On the FUNCTION, not on the door it is called through. The same function may be reached by a REST endpoint, an MCP
tool or a page; it is polled whichever one a machine uses, so it is said once, where the function is. A static
member of a class takes it as a top-level function does.
When you do not need it#
Two other ways tell the linter a function is called on a timer, and need no attribute:
- a workflow reminder's
ThenEvery, or a schedule rule, that runs it more often than once an hour with a literal cadence (Schedule (recurring work)); - an
Endpointof aRestApithat takes an API key and nothing else, or an MCPTool, whose answer is a class with a member namedPollSeconds,LeaseSecondsorNextPollAt. The linter infers a poll from that, at CONSIDER (cost-machine-door-pays-for-what-did-not-change); the attribute makes it a SHOULD and adds the interval.
What the compiler refuses#
- No interval, or one that is not a whole number of seconds from 1 to 86400:
[Polled],[Polled(EverySeconds = 0)],[Polled(5)]. Write[Polled(EverySeconds = 5)]. - Beside an attribute that says the function is not called by a machine on a timer:
[OnStart](it runs when the app is loaded),[On](when its event is raised),[Client](in the browser),[AuthMethod],[Test].
Examples#
A device reports every minute; the report is its own row, written when it moved:
entity Device {
[MaxLength(40)] string Name = "";
int Reading;
security { allow read when IsAuthenticated; }
}
[Polled(EverySeconds = 60)]
void Report(Device device, int reading) {
if (device.Reading != reading) { device.Reading = reading; }
}See also#
- A polled function pays only for what changed — the rule, each shape it finds, and the fix for each
- Cost.Mark() and Cost.StatementsSince(mark) — hold what an idle call costs with a test
- Schedule (recurring work) — work for everybody belongs on a schedule, not on a caller's path