s3-poller
Fetch a JSON object from S3. Poll it for updates. Refetch it only if it has changed.
Usage
Fairly self-documenting. See index.js
comments for nitty-gritty. Here are the basics:
const poller = bucket: 'my-bucket' key: 'path/to/some.json'; poller; // undefinedpoller; // undefined await poller; // fetch from S3await poller; // already cached; returns cached copy ; poller; // Date await poller; // fetch from S3, even if cached, but only if modified since last fetch poller; // call you back when updates happenpoller; // check every hour poller; // remove these listeners poller; // change polling inteval, same listeners poller; // stop polling, listeners stay registered poller; // remove all listeners
(await
is ES7-speak for Promises. You don't need ES7, you can just use .then()
etc.)
Useful constructor options:
bucket
,key
- obvious, requiredinitialValue
- preset the interally cached valuelastModified
- preset the last modified dateupdateInterval
- preset the update interval (ms), AND start polling immediatelyupdateListener
- add an update listener; you can give an array of listeners toos3Config
- this gets passed into theAWS.S3()
constructor call
This thing will barf if the object it receives isn't JSON. You can catch that error from getObject()
or getUpdate()
. Polling just discards the error for the time being.
Legal
Copyright (c) 2016 Datanalytics, Inc. d/b/a Juristat.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: