-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to logs, fix crash in resume review, experience polish (#…
…384) * Ensure we never try to send too large a log * Link back to resume when logging feedback * Fix links in recurring messages * Exclude message author from emoji reaction count, fixes #358 * Add exponential backoff retry helper * Add durability for initial messages fetch, fixes #382
- Loading branch information
Showing
5 changed files
with
70 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* This is a chatGPT generated function, don't blame me. I did verify it works: | ||
```ts | ||
console.log(retryCount, { | ||
backoff: delay * Math.pow(factor, retries - retryCount), | ||
retryCount, | ||
}); | ||
``` | ||
as the first line of the `attempt` function produced: | ||
``` | ||
> 5 { backoff: 20, retryCount: 5 } | ||
> 4 { backoff: 40, retryCount: 4 } | ||
> 3 { backoff: 80, retryCount: 3 } | ||
> 2 { backoff: 160, retryCount: 2 } | ||
> 1 { backoff: 320, retryCount: 1 } | ||
> 0 { backoff: 640, retryCount: 0 } | ||
``` | ||
* Retries a promise-returning function with exponential backoff. | ||
* | ||
* @template T | ||
* @param {() => Promise<T>} fn - The function returning a promise to be retried. | ||
* @param {number} [retries=3] - The number of retry attempts. | ||
* @param {number} [delayMs=1000] - The initial delay in milliseconds before retrying. | ||
* @returns {Promise<T>} A promise that resolves with the result of the function or rejects after all retries have been exhausted. | ||
*/ | ||
export function retry<T>( | ||
fn: () => Promise<T>, | ||
retries = 3, | ||
delayMs = 1000, | ||
): Promise<T> { | ||
return new Promise((resolve, reject) => { | ||
const attempt = (retryCount: number) => { | ||
fn() | ||
.then(resolve) | ||
.catch((error) => { | ||
if (retryCount <= 0) { | ||
reject(error); | ||
} else { | ||
setTimeout(() => { | ||
attempt(retryCount - 1); | ||
}, delayMs * Math.pow(2, retries - retryCount)); | ||
} | ||
}); | ||
}; | ||
|
||
attempt(retries); | ||
}); | ||
} |
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