Skip to content

Conversation

@THardy98
Copy link
Contributor

@THardy98 THardy98 commented Sep 26, 2025

What was changed

Update samples to use client environment configuration.

Why?

Client environment configuration is intended as the preferred way to configure clients going forward.

  1. Part of [Feature Request] Environment configuration #40

  2. How was this tested:
    Existing tests

  3. Any docs updates needed?
    No

@THardy98
Copy link
Contributor Author

Waiting for next Ruby release with env config feature

@THardy98 THardy98 force-pushed the update_samples_env_config branch from 7aa9c6e to 624c4ea Compare November 11, 2025 03:01
@THardy98 THardy98 marked this pull request as ready for review November 11, 2025 03:01
@THardy98 THardy98 requested a review from a team as a code owner November 11, 2025 03:01
@THardy98 THardy98 force-pushed the update_samples_env_config branch 2 times, most recently from f19dbb8 to 7f0d8db Compare November 11, 2025 05:03
@THardy98
Copy link
Contributor Author

The big diff is from the rbi file in the sorbet sample.

@cretz
Copy link
Member

cretz commented Nov 12, 2025

Note, CI is failing and I believe #63 needs to be solved before CI stops failing. I will add a reminder to work on this in a day or two.


# Load config and apply defaults
positional_args, keyword_args = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
positional_args = ['localhost:7233', 'default'] if positional_args.empty?
Copy link
Member

@cretz cretz Nov 12, 2025

Choose a reason for hiding this comment

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

I do wonder, and we may have to discuss separately, what if they set the address in env config but not the namespace? Or vice versa?

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 looked into this, there's a bad behavior here:

def to_client_connect_options
        positional_args = [address, namespace].compact
        ...
end

We shouldn't be compacting positional args, that makes things weird, particularly in the case where namespace is provided by address isn't. I'm opening a PR now to fix that. I'll make the change to these samples to instead do:

positional_args, keyword_args = load_client_connect_options
  address, namespace = positional_args
  address ||= 'localhost:7233'
  namespace ||= 'default'
  client = Client.connect(address, namespace, **keyword_args)

instead of the single check for both positional args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@cretz cretz Nov 12, 2025

Choose a reason for hiding this comment

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

Nice. I also think you can just do:

args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233'` # Default address
args[1] ||= 'default' # Default namespace

@THardy98 THardy98 requested a review from cretz November 12, 2025 21:39
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. I have opened #64 which, when reviewed/merged, will fix CI runs.

'default',
logger: Logger.new($stdout, level: Logger::INFO)
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO))
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal since kwargs can never have logger in it, but usually in Ruby you would recommend the explicit args/kwargs to go before the splatting.

interceptors: [ContextPropagation::Interceptor.new(:my_user)]
)
client = Temporalio::Client.connect(*args, **kwargs, logger: Logger.new($stdout, level: Logger::INFO),
interceptors: interceptors)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
interceptors: interceptors)
interceptors:)

Providing the name that's the same as the kwarg is redundant (this applies in other places too)


# Load config and apply defaults
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args = ["localhost:7233", "default"] if args.empty?
Copy link
Member

Choose a reason for hiding this comment

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

I think this is still the old form and should be the args[0] ||= style

@THardy98 THardy98 force-pushed the update_samples_env_config branch from 55dd4d1 to bf002ae Compare November 19, 2025 17:32
@THardy98 THardy98 merged commit 51b6264 into main Nov 19, 2025
7 checks passed
@THardy98 THardy98 deleted the update_samples_env_config branch November 19, 2025 17:40
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