Osy#betaRun it on Osyrin: osyrin.com

Reference / Function

[Polled] — a function machines call on a timer

[Polled(EverySeconds = <n>)] <Type> <Name>(…) { … }

`[Polled(EverySeconds = 5)]` declares that machines call this function on a timer — a host's poll, a heartbeat, a device's report. It changes nothing about how the function runs. `osy lint` then judges what every call pays when nothing changed (cost-polled-function-pays-for-what-did-not-change) and names the fix for each shape it finds.

preview2 examples compiled by CIfunctioncostlintattribute

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 Endpoint of a RestApi that takes an API key and nothing else, or an MCP Tool, whose answer is a class with a member named PollSeconds, LeaseSeconds or NextPollAt. 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#

Related

A polled function pays only for what changed

osy lint's cost-polled-function-pays-for-what-did-not-change judges a function machines call on a timer — marked…

Cost.Mark() and Cost.StatementsSince(mark)

What a test's unit of work sent to the database between two points: take a mark, do the thing, read what it cost — in…

Schedule (recurring work)

A schedule produces work on a cadence. Each occurrence creates a row of the entity its Template names — carrying…