Module: Hatchet::Clients

Defined in:
lib/hatchet/clients.rb,
lib/hatchet/clients/grpc/admin.rb,
lib/hatchet/clients/grpc/dispatcher.rb,
lib/hatchet/clients/grpc/event_client.rb

Overview

Client implementations for different protocols

Defined Under Namespace

Modules: Grpc

Class Method Summary collapse

Class Method Details

.available_clientsArray<Symbol>

List available client types

Returns:

  • (Array<Symbol>)

    List of available client types



61
62
63
64
65
# File 'lib/hatchet/clients.rb', line 61

def available_clients
  clients = []
  clients << :rest if rest_available?
  clients
end

.rest_available?Boolean

Check if REST client is available

Returns:

  • (Boolean)

    true if REST client has been generated and is available



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hatchet/clients.rb', line 39

def rest_available?
  return false unless defined?(Hatchet::Clients::Rest)

  # Check if this is the real implementation or just the placeholder
  # The placeholder Configuration.from_hatchet_config raises LoadError
  begin
    # Try to access a method that should exist in the real implementation
    # If it's the placeholder, this will raise LoadError
    Hatchet::Clients::Rest::Configuration.method(:from_hatchet_config)

    # Try creating a dummy configuration to ensure the real client is loaded
    dummy_config = Struct.new(:token, :server_url, :listener_v2_timeout).new("test", "", nil)
    Hatchet::Clients::Rest::Configuration.from_hatchet_config(dummy_config)
    true
  rescue LoadError
    false
  end
end

.rest_client(config) ⇒ Hatchet::Clients::Rest::ApiClient

Create a REST API client using the provided Hatchet configuration

Examples:

Create a REST client

config = Hatchet::Config.new(token: "your-jwt-token")
rest_client = Hatchet::Clients.rest_client(config)
workflows_api = Hatchet::Clients::Rest::WorkflowApi.new(rest_client)

Parameters:

Returns:

  • (Hatchet::Clients::Rest::ApiClient)

    Configured REST API client

Raises:

  • (LoadError)

    if REST client hasn’t been generated yet



29
30
31
32
33
34
# File 'lib/hatchet/clients.rb', line 29

def rest_client(config)
  raise LoadError, "REST client not available. Run `rake api:generate` to generate it from the OpenAPI spec." unless rest_available?

  rest_config = Rest::Configuration.from_hatchet_config(config)
  Rest::ApiClient.new(rest_config)
end