Files
Matt Aitken e6861f4fe4 Fix: run page logs keep refreshing when a run finishes (#2971)
Closes #2798

When a run finished the logs UI could get stuck and so be pending and
never update again. If you did a hard reload it would be correct.

This happened because when we insert a log/span we ping Redis which
causes a reload of the UI. However there was a race condition – the
insert into ClickHouse can take a while so we were refreshing the UI too
early. Then never refreshing it again.
  
Changes
- Send refresh pings every 5s to keep run page logs live
- Throttle updates so the run UI is never updated more than once per
second
- Stop auto-reloading when a run has been completed for >= 30s
- Add type inference improvements for the throttle function
<!-- devin-review-badge-begin -->

---

<a
href="https://app.devin.ai/review/triggerdotdev/trigger.dev/pull/2971">
  <picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open with Devin">
  </picture>
</a>
<!-- devin-review-badge-end -->
2026-01-30 09:47:56 +00:00

21 lines
559 B
TypeScript

//From: https://kettanaito.com/blog/debounce-vs-throttle
/** A very simple throttle. Will execute the function at the end of each period and discard any other calls during that period. */
export function throttle<TArgs extends unknown[]>(
func: (...args: TArgs) => void,
durationMs: number
): (...args: TArgs) => void {
let isPrimedToFire = false;
return (...args: TArgs) => {
if (!isPrimedToFire) {
isPrimedToFire = true;
setTimeout(() => {
func(...args);
isPrimedToFire = false;
}, durationMs);
}
};
}