Skip to content
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

Worker client replacement and activity client access #219

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

cretz
Copy link
Member

@cretz cretz commented Feb 10, 2025

What was changed

  • Added Temporalio::Worker#client and Temporalio::Worker#client= to support replacing client on running worker
  • Added Temporalio::Activity::Context#client to support accessing the client from the activity

Checklist

  1. Closes [Feature Request] Worker client replacement #165
  2. Closes [Feature Request] Provide client from activity context #181

@cretz cretz requested a review from a team February 10, 2025 22:19
# @return [Client] Client for this worker. This is the same as {Options.client} in {options}, but surrounded by a
# mutex to be safe for client replacement in {client=}.
def client
@client_mutex.synchronize { @options.client }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to acquire the mutex to read the client? Even during client replacement, that prop would be, at any moment, either the previous client or the new client, which are both valid values.

Copy link
Member Author

@cretz cretz Feb 11, 2025

Choose a reason for hiding this comment

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

While they both may be valid, we would prefer it be the "current" client. In Ruby (and similar languages), people expect an attribute reader to be atomic with an attribute writer of the same name, and they are for simple get/set, but this adds extra to the set side which means we need a mutex to preserve that expectation (and it's basically harmless to do so).

@cretz cretz merged commit 7162d3e into temporalio:main Feb 11, 2025
6 checks passed
@cretz cretz deleted the client-access branch February 11, 2025 15:59
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] Provide client from activity context [Feature Request] Worker client replacement
2 participants