Class: Hatchet::Features::Events
- Inherits:
-
Object
- Object
- Hatchet::Features::Events
- Defined in:
- lib/hatchet/features/events.rb
Overview
Events client for interacting with Hatchet event management API
This class provides a high-level interface for creating and managing events in the Hatchet system. It uses gRPC for event creation (push/bulk_push) and the REST API for read operations (list, get, etc.).
Constant Summary collapse
- CreateEventRequest =
Re-export commonly used event classes for convenience
::HatchetSdkRest::CreateEventRequest
- BulkCreateEventRequest =
::HatchetSdkRest::BulkCreateEventRequest
- EventList =
::HatchetSdkRest::V1EventList
Instance Method Summary collapse
-
#bulk_push(events, namespace: nil) ⇒ Object
Create events in bulk.
-
#cancel(event_ids: nil, keys: nil, since: nil, until_time: nil) ⇒ Object
Cancel events matching the given criteria.
-
#create(key:, data:, additional_metadata: nil, priority: nil, scope: nil, namespace: nil) ⇒ Object
Creates a new event in the Hatchet system.
-
#get(event_id) ⇒ Object
Get a specific event by ID.
-
#get_data(event_id) ⇒ Object
Get event data for a specific event.
-
#initialize(rest_client, event_grpc, config) ⇒ void
constructor
Initializes a new Events client instance.
-
#list(offset: nil, limit: nil, keys: nil, since: nil, until_time: nil, workflow_ids: nil, workflow_run_statuses: nil, event_ids: nil, additional_metadata: nil, scopes: nil) ⇒ HatchetSdkRest::V1EventList
List events with filtering options.
-
#list_keys ⇒ Object
List available event keys for the tenant.
-
#push(event_key, payload, additional_metadata: nil, namespace: nil, priority: nil) ⇒ Object
Push a single event to Hatchet.
-
#replay(event_ids: nil, keys: nil, since: nil, until_time: nil) ⇒ Object
Replay events matching the given criteria.
Constructor Details
#initialize(rest_client, event_grpc, config) ⇒ void
Initializes a new Events client instance
34 35 36 37 38 39 |
# File 'lib/hatchet/features/events.rb', line 34 def initialize(rest_client, event_grpc, config) @rest_client = rest_client @event_grpc = event_grpc @config = config @event_api = HatchetSdkRest::EventApi.new(rest_client) end |
Instance Method Details
#bulk_push(events, namespace: nil) ⇒ Object
Create events in bulk
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/hatchet/features/events.rb', line 110 def bulk_push(events, namespace: nil) grpc_events = events.map do |event| { key: event[:key], payload: event[:data] || {}, additional_metadata: event[:additional_metadata], priority: event[:priority], } end @event_grpc.bulk_push(grpc_events, namespace: namespace) end |
#cancel(event_ids: nil, keys: nil, since: nil, until_time: nil) ⇒ Object
Cancel events matching the given criteria
206 207 208 209 210 211 212 |
# File 'lib/hatchet/features/events.rb', line 206 def cancel(event_ids: nil, keys: nil, since: nil, until_time: nil) cancel_request = HatchetSdkRest::CancelEventRequest.new( event_ids: event_ids, ) @event_api.event_update_cancel(@config.tenant_id, cancel_request) end |
#create(key:, data:, additional_metadata: nil, priority: nil, scope: nil, namespace: nil) ⇒ Object
Creates a new event in the Hatchet system
This method sends an event creation request via gRPC. The event will be processed and made available for workflow triggers and event-driven automation.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hatchet/features/events.rb', line 62 def create(key:, data:, additional_metadata: nil, priority: nil, scope: nil, namespace: nil) @event_grpc.push( key: key, payload: data, additional_metadata: , priority: priority, scope: scope, namespace: namespace, ) end |
#get(event_id) ⇒ Object
Get a specific event by ID
177 178 179 |
# File 'lib/hatchet/features/events.rb', line 177 def get(event_id) @event_api.v1_event_get(@config.tenant_id, event_id) end |
#get_data(event_id) ⇒ Object
Get event data for a specific event
186 187 188 |
# File 'lib/hatchet/features/events.rb', line 186 def get_data(event_id) @event_api.event_data_get_with_tenant(event_id, @config.tenant_id) end |
#list(offset: nil, limit: nil, keys: nil, since: nil, until_time: nil, workflow_ids: nil, workflow_run_statuses: nil, event_ids: nil, additional_metadata: nil, scopes: nil) ⇒ HatchetSdkRest::V1EventList
List events with filtering options
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/hatchet/features/events.rb', line 143 def list( offset: nil, limit: nil, keys: nil, since: nil, until_time: nil, workflow_ids: nil, workflow_run_statuses: nil, event_ids: nil, additional_metadata: nil, scopes: nil ) @event_api.v1_event_list( @config.tenant_id, { offset: offset, limit: limit, keys: keys, since: since&.utc&.iso8601, _until: until_time&.utc&.iso8601, workflow_ids: workflow_ids, workflow_run_statuses: workflow_run_statuses, event_ids: event_ids, additional_metadata: (), scopes: scopes, }, ) end |
#list_keys ⇒ Object
List available event keys for the tenant
194 195 196 |
# File 'lib/hatchet/features/events.rb', line 194 def list_keys @event_api.v1_event_key_list(@config.tenant_id) end |
#push(event_key, payload, additional_metadata: nil, namespace: nil, priority: nil) ⇒ Object
Push a single event to Hatchet
88 89 90 91 92 93 94 95 96 |
# File 'lib/hatchet/features/events.rb', line 88 def push(event_key, payload, additional_metadata: nil, namespace: nil, priority: nil) create( key: event_key, data: payload, additional_metadata: , priority: priority, namespace: namespace, ) end |
#replay(event_ids: nil, keys: nil, since: nil, until_time: nil) ⇒ Object
Replay events matching the given criteria
222 223 224 225 226 227 228 |
# File 'lib/hatchet/features/events.rb', line 222 def replay(event_ids: nil, keys: nil, since: nil, until_time: nil) replay_request = HatchetSdkRest::ReplayEventRequest.new( event_ids: event_ids, ) @event_api.event_update_replay(@config.tenant_id, replay_request) end |