Class: Hatchet::Features::Filters

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

Overview

Filters client for interacting with Hatchet’s filters API

This class provides a high-level interface for creating, retrieving, listing, updating, and deleting filters in the Hatchet system.

Examples:

Listing filters

filters = filters_client.list(limit: 10, workflow_ids: ["wf-1"])

Creating a filter

filter = filters_client.create(
  workflow_id: "wf-1",
  expression: 'input.priority > 5',
  scope: "high-priority"
)

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(rest_client, config) ⇒ void

Initializes a new Filters 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



28
29
30
31
32
# File 'lib/hatchet/features/filters.rb', line 28

def initialize(rest_client, config)
  @rest_client = rest_client
  @config = config
  @filter_api = HatchetSdkRest::FilterApi.new(rest_client)
end

Instance Method Details

#create(workflow_id:, expression:, scope:, payload: nil) ⇒ Object

Create a new filter

Examples:

filter = filters_client.create(
  workflow_id: "wf-1",
  expression: 'input.value > 10',
  scope: "my-scope",
  payload: { threshold: 10 }
)

Parameters:

  • workflow_id (String)

    The ID of the workflow to associate with the filter

  • expression (String)

    The CEL expression to evaluate for the filter

  • scope (String)

    The scope for the filter

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

    The payload to send with the filter

Returns:

  • (Object)

    The created filter

Raises:

Since:

  • 0.1.0



82
83
84
85
86
87
88
89
90
# File 'lib/hatchet/features/filters.rb', line 82

def create(workflow_id:, expression:, scope:, payload: nil)
  request = HatchetSdkRest::V1CreateFilterRequest.new(
    workflow_id: workflow_id,
    expression: expression,
    scope: scope,
    payload: payload,
  )
  @filter_api.v1_filter_create(@config.tenant_id, request)
end

#delete(filter_id) ⇒ Object

Delete a filter by its ID

Examples:

filters_client.delete("filter-123")

Parameters:

  • filter_id (String)

    The ID of the filter to delete

Returns:

  • (Object)

    The deleted filter

Raises:

Since:

  • 0.1.0



99
100
101
# File 'lib/hatchet/features/filters.rb', line 99

def delete(filter_id)
  @filter_api.v1_filter_delete(@config.tenant_id, filter_id)
end

#get(filter_id) ⇒ Object

Get a filter by its ID

Examples:

filter = filters_client.get("filter-123")

Parameters:

  • filter_id (String)

    The ID of the filter to retrieve

Returns:

  • (Object)

    The filter details

Raises:

Since:

  • 0.1.0



63
64
65
# File 'lib/hatchet/features/filters.rb', line 63

def get(filter_id)
  @filter_api.v1_filter_get(@config.tenant_id, filter_id)
end

#list(limit: nil, offset: nil, workflow_ids: nil, scopes: nil) ⇒ Object

List filters for the current tenant

Examples:

filters = filters_client.list(limit: 10, workflow_ids: ["wf-1"])

Parameters:

  • limit (Integer, nil) (defaults to: nil)

    The maximum number of filters to return

  • offset (Integer, nil) (defaults to: nil)

    The number of filters to skip

  • workflow_ids (Array<String>, nil) (defaults to: nil)

    A list of workflow IDs to filter by

  • scopes (Array<String>, nil) (defaults to: nil)

    A list of scopes to filter by

Returns:

  • (Object)

    A list of filters matching the specified criteria

Raises:

Since:

  • 0.1.0



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hatchet/features/filters.rb', line 44

def list(limit: nil, offset: nil, workflow_ids: nil, scopes: nil)
  @filter_api.v1_filter_list(
    @config.tenant_id,
    {
      limit: limit,
      offset: offset,
      workflow_ids: workflow_ids,
      scopes: scopes,
    },
  )
end

#update(filter_id, updates) ⇒ Object

Update a filter by its ID

Examples:

filters_client.update("filter-123", { expression: 'input.value > 20' })

Parameters:

  • filter_id (String)

    The ID of the filter to update

  • updates (Hash)

    The updates to apply to the filter

Returns:

  • (Object)

    The updated filter

Raises:

Since:

  • 0.1.0



111
112
113
114
# File 'lib/hatchet/features/filters.rb', line 111

def update(filter_id, updates)
  update_request = HatchetSdkRest::V1UpdateFilterRequest.new(updates)
  @filter_api.v1_filter_update(@config.tenant_id, filter_id, update_request)
end