Polling Triggers
Polling triggers allow you to poll for new events by periodically fetching records and comparing them with previously fetched records.
Example#
async function fetchAllUsers() {// fetch and return list of all Users from oldest to newest// this should be an array of objects with `id` property}const allUsers = await fetchAllUsers();// compute new id snapshotconst newIdSnapshot = new Set(allUsers.map((a) => a.id));// determine new Users added since previous snapshotconst newUserIds = utils.diffIdSnapshot(newIdSnapshot, context.prevIdSnapshot);// events is an array of objects of the Trigger Payload shapeconst events = allUsers.filter((a) => newUserIds.has(a.id)).map((a) => utils.flattenTriggerPayload(a));return {newIdSnapshot,events,};
Polling execution context#
Claim | Type | Description |
---|---|---|
prevIdSnapshot | Set<string> | The set of polled IDs returned from previous poll |
authData | object | The object holding the auth data from JWT / OAuth |
Polling execution return value#
Claim | Type | Description |
---|---|---|
nextIdSnapshot | Set<string> | The set of polled IDs in this poll |
events | object[] | An array of new events - objects of the Trigger Payload shape. |