|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'temporalio/client' |
| 4 | +require 'temporalio/env_config' |
| 5 | + |
| 6 | +def main |
| 7 | + puts '--- Loading default profile from config.toml ---' |
| 8 | + |
| 9 | + # For this sample to be self-contained, we explicitly provide the path to |
| 10 | + # the config.toml file included in this directory. |
| 11 | + # By default though, the config.toml file will be loaded from |
| 12 | + # ~/.config/temporalio/temporal.toml (or the equivalent standard config directory on your OS). |
| 13 | + config_file = File.join(__dir__, 'config.toml') |
| 14 | + |
| 15 | + # load_client_connect_options is a helper that loads a profile and prepares |
| 16 | + # the configuration for Client.connect. By default, it loads the |
| 17 | + # "default" profile. |
| 18 | + args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options( |
| 19 | + config_source: Pathname.new(config_file) |
| 20 | + ) |
| 21 | + |
| 22 | + puts "Loaded 'default' profile from #{config_file}." |
| 23 | + puts " Address: #{args[0]}" |
| 24 | + puts " Namespace: #{args[1]}" |
| 25 | + puts " gRPC Metadata: #{kwargs[:rpc_metadata]}" |
| 26 | + |
| 27 | + puts "\nAttempting to connect to client..." |
| 28 | + begin |
| 29 | + client = Temporalio::Client.connect(*args, **kwargs) |
| 30 | + puts '✅ Client connected successfully!' |
| 31 | + sys_info = client.workflow_service.get_system_info(Temporalio::Api::WorkflowService::V1::GetSystemInfoRequest.new) |
| 32 | + puts "✅ Successfully verified connection to Temporal server!\n#{sys_info}" |
| 33 | + rescue StandardError => e |
| 34 | + puts "❌ Failed to connect: #{e}" |
| 35 | + end |
| 36 | +end |
| 37 | + |
| 38 | +main if $PROGRAM_NAME == __FILE__ |
0 commit comments