Change polling
This is the official documentation of the @forestadmin/agent
Node.js agent.
Fetching all the data from the target API at each update is not always possible, as it may be too slow, too expensive, or over the API rate limit.
Another strategy is to poll for changes on the target API and only fetch the records that changed.
This strategy is called "change polling".
Choosing when to poll for changes
The following events are available:
pullDeltaOnRestart
: When true, your handler will be called on each agent restartpullDeltaOnSchedule
: if set to a cron-like schedule, your handler will be called on that schedule. The syntax is the same as forpullDumpOnSchedule
pullDeltaOnBeforeAccess
: When true, your handler will be called before each access to the data source and the GUI will block until the handler returnspullDeltaOnAfterWrite
: When true, your handler will be called after each write to the data source and the GUI will block until the handler returns
And an extra option is available to allow event grouping: pullDeltaOnBeforeAccessDelay
This value in milliseconds will add a delay to all read requests that are sent to your agent. This delay will allow your agent to group multiple requests that are sent during this delay and call your handler only once.
You can set this value to 0 to disable this feature or find a good balance between the number of calls to the target API and an acceptable delay.
Programming your handler
To be able to fetch only the records that changed, you need to implement a pullDeltaHandler
function.
To know which records may have changed: a state object is preserved between calls, and you are allowed to read from the cache.
Example
Last updated
Was this helpful?