Skip to content

Conversation

@dandavison
Copy link
Contributor

@dandavison dandavison commented Sep 28, 2025

This sample shows how to create a Nexus service that is backed by a long-running workflow and
exposes operations that execute updates and queries against that workflow. The long-running
workflow, and the updates/queries are private implementation detail of the nexus service: the caller
does not know how the operations are implemented.

See temporalio/features#664

  • The sample uses the same workflow as our message_passing/introduction sample for the entity workflow backing the handler.
  • The sample does not currently feature a signal, but that would be very similar. We could refactor the backing handler entity workflow so that the approve signal does not terminate the workflow, as it does currently.

@dandavison dandavison force-pushed the nexus-sync-operations-against-workflow branch from 3eab7c0 to 9fe1869 Compare September 28, 2025 21:14
@dandavison dandavison force-pushed the nexus-sync-operations-against-workflow branch 2 times, most recently from 9538e1d to 86c40ea Compare September 29, 2025 12:46
@dandavison dandavison force-pushed the nexus-sync-operations-against-workflow branch from 86c40ea to 78b2f52 Compare September 29, 2025 13:16
@dandavison dandavison marked this pull request as ready for review September 29, 2025 13:16
@dandavison dandavison requested a review from a team as a code owner September 29, 2025 13:16
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Nothing blocking


from temporalio import workflow

from message_passing.introduction import Language
Copy link
Member

Choose a reason for hiding this comment

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

We had traditionally had all samples self-contained in all of our SDKs (i.e. they didn't reference each other), but maybe that's no longer what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's allow this one to reference. IMO it is educational / instructive: it's showing users that nexus allows a "service" to be transplanted without changes and given a nexus interface callable from another namespace.

supported_languages = await nexus_client.execute_operation(
GreetingService.get_languages, GetLanguagesInput(include_unsupported=False)
)
print(f"supported languages: {supported_languages}")
Copy link
Member

Choose a reason for hiding this comment

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

Would discourage use of print in workflows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, changed to return log: list[str]

Copy link
Member

Choose a reason for hiding this comment

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

I was under the impression we are only doing this "description" markdown on the "hello" Nexus sample? Do we need to start doing this for all samples?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I think all nexus endpoints in samples should have a description. The feature exists and we want to encourage users to use it, and it is nicely rendered in the UI.


# 👉 This is a handler for a nexus operation whose internal implementation involves executing an
# update against a long-running workflow that is private to the nexus service.
@nexusrpc.handler.sync_operation
Copy link
Member

Choose a reason for hiding this comment

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

In theory an update can be long running and we should demonstrate async operation with it, but I understand if we need some kind of server side support for update callbacks or something for that. May be worth noting though, up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a note explaining that updates must be fast when used in a sync operation. Yes, async nexus operations backed by updates do not exist yet and would require server-side nexus callback support in the server-side update state machine.

@dandavison dandavison merged commit e4f2442 into main Sep 30, 2025
11 checks passed
@dandavison dandavison deleted the nexus-sync-operations-against-workflow branch September 30, 2025 13:21
@dandavison dandavison changed the title nexus_sync_operations Nexus sync operations that send messages to an entity workflow Oct 1, 2025
THardy98 pushed a commit that referenced this pull request Nov 10, 2025
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.

3 participants