Class: Hatchet::Features::CEL

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/features/cel.rb

Overview

CEL client for debugging CEL expressions within Hatchet

This class provides a high-level interface for testing and debugging CEL (Common Expression Language) expressions used in filters and conditions.

Examples:

Debugging a CEL expression

result = cel_client.debug(
  expression: 'input.value > 10',
  input: { value: 15 }
)
if result.result.status == 'success'
  puts "Output: #{result.result.output}"
else
  puts "Error: #{result.result.error}"
end

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(rest_client, config) ⇒ void

Initializes a new CEL client instance

Parameters:

  • rest_client (Object)

    The configured REST client for API communication

  • config (Hatchet::Config)

    The Hatchet configuration containing tenant_id and other settings

Since:

  • 0.1.0



44
45
46
47
48
# File 'lib/hatchet/features/cel.rb', line 44

def initialize(rest_client, config)
  @rest_client = rest_client
  @config = config
  @cel_api = HatchetSdkRest::CELApi.new(rest_client)
end

Instance Method Details

#debug(expression:, input:, additional_metadata: nil, filter_payload: nil) ⇒ CELEvaluationResult

Debug a CEL expression with provided input and optional metadata

Useful for testing and validating CEL expressions and debugging issues in production.

Examples:

result = cel_client.debug(
  expression: 'input.count > 5 && metadata.env == "prod"',
  input: { count: 10 },
  additional_metadata: { env: 'prod' }
)

Parameters:

  • expression (String)

    The CEL expression to debug

  • input (Hash)

    The input, which simulates the workflow run input

  • additional_metadata (Hash, nil) (defaults to: nil)

    Additional metadata simulating metadata sent with an event or workflow run

  • filter_payload (Hash, nil) (defaults to: nil)

    The filter payload simulating a payload set on a previously-created filter

Returns:

Raises:

  • (RuntimeError)

    If no response is received from the CEL debug API

  • (HatchetSdkRest::ApiError)

    If the API request fails

Since:

  • 0.1.0



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/hatchet/features/cel.rb', line 67

def debug(expression:, input:, additional_metadata: nil, filter_payload: nil)
  request = HatchetSdkRest::V1CELDebugRequest.new(
    expression: expression,
    input: input,
    additional_metadata: ,
    filter_payload: filter_payload,
  )

  result = @cel_api.v1_cel_debug(@config.tenant_id, request)

  if ["ERROR", :ERROR].include?(result.status)
    raise "No error message received from CEL debug API." if result.error.nil?

    return CELEvaluationResult.new(result: CELFailure.new(error: result.error))
  end

  raise "No output received from CEL debug API." if result.output.nil?

  CELEvaluationResult.new(result: CELSuccess.new(output: result.output))
end