-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Make project deployable to local k8s
- Loading branch information
1 parent
b8d5d1a
commit c54b5e3
Showing
46 changed files
with
691 additions
and
829 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import fetch from "node-fetch" | ||
|
||
import { logger } from "../logger.js" | ||
|
||
export type FetchParams = { | ||
endpoint: string, | ||
options: Object | ||
} | ||
|
||
export type RetryOptions = { | ||
retries: number, | ||
retryDelay: number, | ||
fetchParams: FetchParams | ||
} | ||
|
||
export const invoke = async (options: RetryOptions, apiBody: Object) => { | ||
let attempts = 1 | ||
while (options.retries > 0) { | ||
logger.info("lock-manager-api-client.invoke(): attempt %s of %s invoking %s", attempts, options.retries, JSON.stringify(options.fetchParams)) | ||
try { | ||
return await invokeApi(options.fetchParams, apiBody) | ||
} catch (error) { | ||
logger.warn("lock-manager-api-client.invoke(): attempt %s of %s invoking %s. Error: %s", attempts, options.retries, JSON.stringify(options.fetchParams), error) | ||
if (attempts < options.retries) { | ||
attempts++ | ||
await sleep(options.retryDelay) | ||
continue | ||
} | ||
|
||
logger.warn("lock-manager-api-client.invoke(): failed to invoke %s. No more attempts left, giving up", JSON.stringify(options.fetchParams)) | ||
throw new Error(`Failed to fetch ${ options.fetchParams.endpoint } after ${ attempts } attempts`, { cause: error }) | ||
} | ||
} | ||
} | ||
|
||
const invokeApi = async (params: FetchParams, apiBody: Object) =>{ | ||
let resp = await fetch(params.endpoint, { ...params.options, body: JSON.stringify(apiBody) }) | ||
// TODO: check for JSON header before decoding | ||
return await resp.json() | ||
} | ||
|
||
export const sleep = (time: number) => new Promise(resolve => setTimeout(resolve, time)) |
Oops, something went wrong.