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:
queryrequired:tasks,jobs,agentsorlan_peers, as the App query block reads them.every_minutesrequired: 1 to 1440.holder,state,pr(tasks) andjob(jobs, required: the runs of that one job),limit(both): the App query’s own filters. An answer is cut tolimit, 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.agentslists at most 20 problems.include_existingoptional 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:
taskseach task, by its number.jobseach run of the named job, by its id.agentseach 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_peerseach 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§
- Poll
State - The poller’s memory: one entry per poll job.
Enums§
- Poll
Kind - Which poll jobs a pass looks at. The
apiquestions go out over the network and can take their whole timeout each, so they are a pass of their own (seespawn): an outage on an external site must not hold up the local polls and theexpectchecks (the dead-man’s switch) that run beside them.
Constants§
- API_
ASKS_ AT_ ONCE - How many
apiquestions 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
apikeeps when the filter gives nolimit, 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.
nowis a parameter so a test can step the clock. - poll_
due_ of poll_duefor the jobs of onePollKind. The due questions are asked first, theapiones 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
expectjobs.checkanswers the App query. Theapipolls run in a task of their own, so a site that does not answer holds up nothing else. - validate_
filter - A
polltrigger’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.