Skip to content

break out startUpdate vs executeUpdate #107

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
merged 3 commits into from
May 14, 2025
Merged

break out startUpdate vs executeUpdate #107

merged 3 commits into from
May 14, 2025

Conversation

johnmastro
Copy link
Contributor

@johnmastro johnmastro commented May 13, 2025

refactor update into:

  • startUpdate, which returns an UpdateHandle without waiting for the update to complete. but note that startUpdate does wait for the validator (if any) to complete (i.e. that the update reaches the ACCEPTED stage) so that we can signal an UpdateFailed error for validator failures rather than an "update not found" RpcError (which is what would happen if we tried to poll for the outcome where the validator rejected the update). this is the same thing the typescript sdk does.
  • waitForUpdateOutcome, which, given an UpdateHandle, waits for it to complete and returns the result
  • executeUpdate, which composes those two start the update and wait for its result (the same behavior as the original update)

Copy link

linear bot commented May 13, 2025

@johnmastro johnmastro changed the title break out startUpdate vs executeUpdate break out startUpdate vs executeUpdate May 14, 2025
@@ -139,7 +140,7 @@ import Unsafe.Coerce
-- WorkflowClient stuff

workflowClient
:: MonadIO m
:: (MonadIO m)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm not sure if the precommit hook made these formatting changes, or zed (which i took for a test drive here), or what, but i can change it back if anyone hates them

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried zed and it did this too. I set "format_on_save": "off" in the config to make it a bit less aggressive about doing this. I don't particularly mind the change though

@@ -97,8 +97,8 @@ updateWithValidatorThatThrows = provideCallStack do
registerWorkflow 'updateWithValidatorThatThrows


updateWithValidatorThatSleeps :: Workflow Int
updateWithValidatorThatSleeps = provideCallStack do
updateThatSleeps :: Workflow Int
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i happened to notice that the old name was a misnomer (there's no validator, and validation isn't relevant to the tests that use it)

@johnmastro johnmastro marked this pull request as ready for review May 14, 2025 13:31
@johnmastro johnmastro requested a review from iand675 May 14, 2025 13:31
UpdateLifecycleStageAdmitted -> Update.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ADMITTED
UpdateLifecycleStageAccepted -> Update.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED
UpdateLifecycleStageCompleted -> Update.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_COMPLETED
& Update.lifecycleStage .~ Update.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED
Copy link
Contributor

Choose a reason for hiding this comment

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

I initially thought this was wrong, but I guess you're able to poll later for other lifecycle stages, so 👍🏻

or throw an exception if the update failed.
-}
waitForUpdateOutcome :: (MonadIO m) => UpdateHandle a -> m a
waitForUpdateOutcome h = do
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we name this waitUpdateResult to match the waitWorkflowResult function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just pushed a commit doing this

)
`shouldThrow` \case
UpdateFailure _ -> True
_ -> False
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless UpdateFailure has other constructors, these pattern matches are redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, right. what i really want to test here is that we threw an UpdateFailure and not, for example, an RpcError.

reading the hspec docs, it sounds like i would want to write a selector for that. is that right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you are testing that on line 1599. You just don't need the wildcard match to do that because you've already constrained the type by pattern matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, i see. all right, just pushed a commit to remove the redundant branches

@johnmastro johnmastro merged commit 93d8c73 into main May 14, 2025
14 checks passed
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.

2 participants