Skip to content

Conversation

ianshade
Copy link
Contributor

@ianshade ianshade commented Jul 24, 2025

About the Contributor

This pull request is posted on behalf of TV 2 Norge.

Type of Contribution

This is a:

Feature

Current Behavior

Not possible to queue a part from onTake()

New Behavior

Blueprints can queue a dynamic part during the onTake() callback. A queuePartAfterTake() method was added IOnTakeContext. Naming of the method is quite verbose, to make it clear that it queues the new part after the part currently being Taken. In the future there might be a need to add another method that e.g. queues a part instead of performing the Take.

Testing

  • I have added one or more unit tests for this PR
  • I have updated the relevant unit tests
  • No unit test changes are needed for this PR

Affected areas

This PR affects the playout logic, specifically what happens during a Take. It introduces a non-breaking addition to the Blueprints API.

Time Frame

Other Information

Status

  • PR is ready to be reviewed.
  • The functionality has been tested by the author.
  • Relevant unit tests has been added / updated.
  • Relevant documentation (code comments, system documentation) has been added / updated.

@ianshade ianshade requested a review from a team as a code owner July 24, 2025 06:25
@codecov-commenter
Copy link

codecov-commenter commented Jul 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 62.06897% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/job-worker/src/playout/take.ts 62.50% 9 Missing ⚠️
...job-worker/src/blueprints/context/OnTakeContext.ts 60.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@jstarpl jstarpl added Contribution External contribution Contribution from TV 2 Norge Contributions sponsored by TV 2 Norge (tv2.no) labels Jul 24, 2025
Copy link
Member

@Julusian Julusian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that returning this function and reusing the actionService is not the best way to achieve this.

I would prefer this to:

  • In the queuePartAfterTake method, perform the relevant bits of the validation that the actionService currently performs, stopping before insertQueuedPartWithPieces.
  • partToQueue in the context should then contain the newPart and pieces that this generates as part of the validation/processing
  • Instead of calling your returned queuePart callback, perform the insertQueuedPartWithPieces call

As a bonus, the validation moving will mean that the blueprint call to queuePartAfterTake will throw errors instead of them being thrown later when they will likely stop the take from happening.

await queuePart()
} else {
// Once everything is synced, we can choose the next part
await setNextPart(context, playoutModel, nextPart, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The definition of nextPart would be good to move into this else block, so that it is only run when needed and make sure it doesnt get used elsewhere accidentally

if (onSetAsNextContext.partToQueue) {
const partToQueue = onSetAsNextContext.partToQueue
queuePart = async () => {
await actionService.queuePart(partToQueue.rawPart, partToQueue.rawPieces)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like how this function gets returned, and am also wondering does this even work correctly?

Largely because this working is reliant on the nextPartState in the service as being NONE. So if any other changes are made to the current part in the callback then this will fail.

Being pickier (perhaps too much so), this relies on the implementation detail of how the actionService gets currentPartInstance. If that were changed to be a less dynamic reference, then this would break (I am pretty sure that nowhere else relies on this mutability).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Contribution from TV 2 Norge Contributions sponsored by TV 2 Norge (tv2.no) Contribution External contribution
Development

Successfully merging this pull request may close these issues.

4 participants