Skip to main content

Module poll

Module poll 

Source
Expand description

A job on the poll source asks AgentMux’s own state a question every so often and starts one run for each item that is new in the answer (docs/specs/SPEC_DRONE_REAL_WORLD_JOBS_2026_11_11.md §3.2). Polling spends no agent tokens: the question is one of the App query’s, answered by srv.

The job’s filter says what to ask and how often:

  • query required: tasks, jobs, agents or lan_peers, as the App query block reads them.
  • every_minutes required: 1 to 1440.
  • holder, state, pr (tasks) and job (jobs, required: the runs of that one job), limit (both): the App query’s own filters. An answer is cut to limit, which a poll leaves at the most the query gives (200 tasks, 100 runs): a new item past the cut, because more than that appeared between two looks, is never seen. agents lists at most 20 problems.
  • include_existing optional true: the items that are already there when the job is turned on run too. Left out, the first poll only takes note of them, so turning a job on does not start a run for everything that happened before.

What counts as an item, and what makes it new:

  • tasks each task, by its number.
  • jobs each run of the named job, by its id.
  • agents each agent that is wanted running and is not up, by its name and state: an agent that goes down again in another way is new.
  • lan_peers each machine, by its host name.

The run reads {{trigger.query}}, {{trigger.key}} (the item’s id) and {{trigger.item}} (the item as the query lists it). An item is never reported twice: the job’s event ids (backend::storage::job_events) remember it for a week, and an item that is still in the answer is remembered for as long as it is there. (An item that is still there when srv restarts more than a week after it was reported is reported again: its id has been forgotten.) A poll that finds more than MAX_NEW_PER_POLL new items starts that many and leaves the rest for the next poll. A poll whose question fails (the ledger is not ready yet, say) is skipped and asked again at the next time.

Structs§

PollState
The poller’s memory: one entry per poll job.

Enums§

PollKind
Which poll jobs a pass looks at. The api questions go out over the network and can take their whole timeout each, so they are a pass of their own (see spawn): an outage on an external site must not hold up the local polls and the expect checks (the dead-man’s switch) that run beside them.

Constants§

API_ASKS_AT_ONCE
How many api questions one pass asks at once. Each may wait out its own timeout on a site that is down, so they are asked together, but not without a bound: a pass of dozens of jobs must not open dozens of connections.
API_DEFAULT_ITEMS
How many items a poll of api keeps when the filter gives no limit, and the most it ever keeps.
API_MAX_ITEMS
MAX_EVERY_MINUTES
MAX_NEW_PER_POLL
The most new items one poll starts a run for.
MIN_API_EVERY_MINUTES
How often a poll may ask a site outside AgentMux: not more than every few minutes, so a drone cannot spend a site’s rate limit (or the person’s API quota) in a minute.
MIN_EVERY_MINUTES
QUERIES
The questions a poll may ask.

Functions§

poll_due
Asks the question of every poll job that is due and starts a run for each new item. Returns how many runs it started or queued. now is a parameter so a test can step the clock.
poll_due_of
poll_due for the jobs of one PollKind. The due questions are asked first, the api ones a few at a time and the rest one after another, and the answers are then handled in the jobs’ order.
spawn
Start the poller, which also looks after the expect jobs. check answers the App query. The api polls run in a task of their own, so a site that does not answer holds up nothing else.
validate_filter
A poll trigger’s filter: the question, how often, and the question’s own filters.

Type Aliases§

Check
Asks the App query filter["query"] with the filter’s own keys and returns its answer. Supplied by the binary, which has the App query; the tests supply a fake.