Skip to content

Library: poll clip readiness one pass at a time - #50

Closed
pallaoro wants to merge 2 commits into
mainfrom
media-poll-one-pass
Closed

pallaoro wants to merge 2 commits into
mainfrom
media-poll-one-pass

Conversation

@pallaoro

@pallaoro pallaoro commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Targets main and includes #44's commit (same hook). Merge in either order: if #44 merges first, its change is already identical here; if this merges first, #44 has nothing left and can be closed.

useMediaReady asked about each pending clip in turn and started a new pass every 5 s with setInterval, whether or not the previous pass had finished. A /playback answer takes ~1.7 s, so a pass over a few hundred clips runs for minutes. The passes piled up, and each one kept asking about every clip, including after the hook's set had changed: dead was only checked once the whole loop was done.

  • src/shared/passes.ts: repeatPasses(pass, gapMs) runs a pass, waits gapMs after it finishes, then runs the next one. It never runs two at once. stop() cancels the next pass, and the pass under way sees stopped() and gives up partway.
  • useMediaReady uses it, and checks stopped() before each clip.

Test (test/passes.test.ts): models 400 clips at 1.7 s each against a 5 s gap. Run against the old setInterval loop, the same test reaches 137 passes at once, and it fails 3 of its 4 cases.

vitest: 136 passed. footage and highlights fail to import @clawnify/queue in my local install, the same as on the base branch.

A clip whose ingest ended in the media service's "error" state never
becomes ready, but the library kept asking about it every 5 seconds for
as long as the editor stayed open. Such clips now drop out of the poll
and their tile says they could not be prepared.
useMediaReady asked about each pending clip in turn and started a new pass
every 5 s with setInterval, whether or not the last pass had finished. A
pass over a few hundred clips takes minutes, so the passes piled up (over a
hundred at once in the test's model) and each one went on asking about every
clip, including after the hook had moved on.

Passes now run through repeatPasses: the next one starts 5 s after the last
finishes, and a pass stops partway once the set it was asked about changes.
@pallaoro
pallaoro changed the base branch from media-error-stop-polling to main October 9, 2026 19:16
@pallaoro

Copy link
Copy Markdown
Member Author

Superseded by #60, merged and deployed 2026-10-10: this PR's commit was cherry-picked onto today's main with its author kept (88f5567 → d5117be, 4bb67d5 → 22e6694), plus one addition: a clip that is gone (404, or 502 not_found from the media service) also stops being polled.

@pallaoro pallaoro closed this Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant