Skip to content

Drop all post-terminal commands & sort activation jobs #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Sushisource
Copy link
Member

@Sushisource Sushisource commented Mar 6, 2023

What was changed

Drop & warn about commands following a terminal workflow command.
Also ensure jobs are sorted in the order langs are expecting anyways before sending them out.

Why?

We'll end up blowing up server-side right now, which is a bit annoying for a user to fix when we can do this instead - and not require lang layer to do it.
De-dupe lang job-sorting work and move it into core.

Checklist

  1. Closes [Feature Request] Discard post-terminal non-query commands #497 and closes [Feature Request] Sort activation jobs by desired execution order #498

  2. How was this tested:
    Added UTs. Existing tests.

  3. Any docs updates needed?

@Sushisource Sushisource changed the title Drop all post-terminal commands Drop all post-terminal commands & sort activation jobs Mar 7, 2023
/// Sorts jobs in an activation to be in the order lang expects:
/// `patches -> signals -> other -> queries`
fn sort_act_jobs(wfa: &mut WorkflowActivation) {
wfa.jobs.sort_by(|j1, j2| {
Copy link
Member

Choose a reason for hiding this comment

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

Can you confirm this is a "stable" sort (meaning equal things aren't reordered)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's stable.

(workflow_activation_job::Variant::NotifyHasPatch(_), _) => Ordering::Less,
(workflow_activation_job::Variant::SignalWorkflow(_), _) => Ordering::Less,
(workflow_activation_job::Variant::QueryWorkflow(_), _) => Ordering::Greater,
_ => Ordering::Equal,
Copy link
Member

Choose a reason for hiding this comment

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

Can you confirm just for my reading that this case should never be hit because of the discriminant(j1v) == discriminant(j2v) check above? (fine to remain for exhaustion, I just want to confirm that the match clause never compares equal elements)

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it never does.

}
match (j1v, j2v) {
(workflow_activation_job::Variant::NotifyHasPatch(_), _) => Ordering::Less,
(workflow_activation_job::Variant::SignalWorkflow(_), _) => Ordering::Less,
Copy link
Member

Choose a reason for hiding this comment

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

What if j1v is SignalWorkflow and j2v is NotifyHasPatch? I think you should give integer ordinals to each job and then cmp them.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a reasonable way to do it. Changed.

@Sushisource Sushisource force-pushed the discard-post-term-commands branch from 4f167bd to 260a568 Compare March 8, 2023 23:32
@Sushisource Sushisource merged commit 65618aa into temporalio:master Mar 9, 2023
@Sushisource Sushisource deleted the discard-post-term-commands branch March 9, 2023 18:13
Sushisource added a commit to Sushisource/sdk-core that referenced this pull request Mar 17, 2023
* Drop all post-terminal commands
* Sort outgoing jobs in order lang expects
Sushisource added a commit to Sushisource/sdk-core that referenced this pull request May 12, 2023
* Drop all post-terminal commands
* Sort outgoing jobs in order lang expects
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.

[Feature Request] Sort activation jobs by desired execution order [Feature Request] Discard post-terminal non-query commands
3 participants