Indexed counts

Count a queue by state and by campaign with no where clause, and run the same count for one campaign through a declared read.

read Schema: schema.yaml
selectaggregateread
docs/site/examples/src/indexed-count/1-counts.yamlyaml
# Queue depth by state and by campaign, then the same count for one
# campaign through the declared read. Reads only, so no request id.
statements:
  - select:
      from: sends
      aggregate: {n: count}
      group_by: [state]
      order_by: [{field: state}]
      limit: 4
  - select:
      from: sends
      aggregate: {n: count}
      group_by: [campaign]
      order_by: [{field: campaign}]
      limit: 100
  - read: {name: campaign_depth, version: 1, params: {campaign: c7}}

After the other examples this returns complete 1 and pending 3, then c7 with 4, then the per-state counts for c7. Each aggregate reads one btree index, (state, due_at, attempts) or (campaign, id), so the rows counted are not capped. A lease that has expired counts as pending without a write. A count grouped by an unindexed field such as step has no index to read and is refused unless its where has an access term.

Programs that write carry a fixed issued_at here. Set it to the time you create the request id, and resend it unchanged on every retry. Ids and tokens come from earlier responses and are passed as params.

All examples · Next: Enqueue, claim, settle