@waylay/plugs-retry
v1.1.0
Published
Utility library for waylay plug writers that provides a retry mechanism.
Downloads
3
Readme
plugs-retry
Utility library for waylay plug writers that provides a retry mechanism.
Usage
Use this library when authoring a Waylay Sensor plug. In the plug editor:
- declare a plug library dependency to
@waylay/plugs-retry
- use the
withRetry
function wrapper in your code to convert a function to a retrying one:
const axios = require('axios')
const withRetry = require('@waylay/plugs-retry')
// actual plug code, uses the extra `retry` keyword to issue retries.
async function tryFetchSomeContent ({options, send, retry, console}) {
const pollURL = options.requiredProperties.pollURL
try {
const response = await axios.get(pollURL, {timeout: 5000})
send(null, { observedState: 'Found', rawData: {content: response.data}})
} catch (error) {
if (error.response) {
const statusCode = error.response.status
if (statusCode === 404) {
retry(error, {observedState: 'Not Found', rawData: {}})
} else if (statusCode >= 500) {
retry(error)
} else {
send(error)
}
} else {
send(error)
}
}
// retry configuration, in this case uses the `retry` plug property to provide overrides
const retryConfig = Object.assign({retries:10, maxSleep: 2000}, options.requiredProperties.retry)
// wrap your function with a retry mechanism, and invoke with plug context
withRetry(tryFetchSomeContent, retryConfig)({options, send, console, waylay})
Documentation
See docs.waylay.io for general information and limitations of this feature.
See sdk.waylay.io for the detailed api description of this extension library.co