-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/node-gracefull-shutdown
- Loading branch information
Showing
15 changed files
with
223 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const { | ||
Transport: LokkaTransportHttp, | ||
} = require('@lagoon/lokka-transport-http'); | ||
const fetchUrl = require('node-fetch'); | ||
|
||
class NetworkError extends Error {} | ||
class ApiError extends Error {} | ||
|
||
// Retries the fetch if operational/network errors occur | ||
const retryFetch = (endpoint, options, retriesLeft = 5, interval = 1000) => | ||
new Promise((resolve, reject) => | ||
fetchUrl(endpoint, options) | ||
.then(response => { | ||
if (response.status !== 200 && response.status !== 400) { | ||
throw new NetworkError(`Invalid status code: ${response.status}`); | ||
} | ||
|
||
return response.json(); | ||
}) | ||
.then(({ data, errors }) => { | ||
if (errors) { | ||
const error = new ApiError(`GraphQL Error: ${errors[0].message}`); | ||
error.rawError = errors; | ||
error.rawData = data; | ||
throw error; | ||
} | ||
|
||
resolve(data); | ||
}) | ||
.catch(error => { | ||
// Don't retry if limit is reached or the error was not network/operational | ||
if (retriesLeft === 1 || error instanceof ApiError) { | ||
reject(error); | ||
return; | ||
} | ||
|
||
setTimeout(() => { | ||
retryFetch(endpoint, options, retriesLeft - 1).then(resolve, reject); | ||
}, interval); | ||
}), | ||
); | ||
|
||
class Transport extends LokkaTransportHttp { | ||
constructor(endpoint, options = {}) { | ||
super(endpoint, options); | ||
} | ||
|
||
send(query, variables, operationName) { | ||
const payload = { query, variables, operationName }; | ||
const options = this._buildOptions(payload); | ||
|
||
return retryFetch(this.endpoint, options); | ||
} | ||
} | ||
|
||
module.exports = { | ||
Transport, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 103 additions & 75 deletions
178
services/webhook-handler/newman/lagoon-webhook-handler.postman_collection.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters