Enqueue, claim, settle
Insert three sends, lease the due ones in claim order, then complete one and retry the other in the same program.
Every example runs against one space, declared by the shared schema
below. Each document on these pages is a file under
docs/site/examples/src/, shown unchanged; the site gate
checks it against the schema and API-008's grammar.
Insert three sends, lease the due ones in claim order, then complete one and retry the other in the same program.
Create a keyed row once, advance it with compare-and-set on its version, and enqueue a send only when a guard finds no suppression row.
Count a queue by state and by campaign with no where clause, and run the same count for one campaign through a declared read.
# One space for a campaign: a queue of sends, a keyed table of admission
# chunks, a suppression table and a declared read.
version: 1
queues:
sends:
max_attempts: 5
retention: 7d
fields:
campaign: {type: text, index: true}
address: {type: text, index: true}
step: {type: int}
tables:
chunks:
key: [run, chunk]
fields:
run: {type: text}
chunk: {type: int}
cursor: {type: int, merge: non_decreasing}
suppression:
key: [address]
fields:
address: {type: text}
reasons: {type: text_set, merge: add_only}
reads:
- name: campaign_depth
version: 1
params: {campaign: text}
select:
from: sends
where: {eq: [campaign, {param: campaign}]}
aggregate: {n: count}
group_by: [state]
order_by: [{field: state}]
limit: 4