Class: Hatchet::Features::Scheduled
- Inherits:
-
Object
- Object
- Hatchet::Features::Scheduled
- Defined in:
- lib/hatchet/features/scheduled.rb
Overview
Scheduled client for managing scheduled workflows within Hatchet
This class provides a high-level interface for creating, deleting, updating, bulk operations, listing, and retrieving scheduled workflow runs.
Instance Method Summary collapse
-
#bulk_delete(scheduled_ids: nil, workflow_id: nil, parent_workflow_run_id: nil, parent_step_run_id: nil, statuses: nil, additional_metadata: nil) ⇒ Object
Bulk delete scheduled workflow runs.
-
#bulk_update(updates) ⇒ Object
Bulk reschedule scheduled workflow runs.
-
#create(workflow_name:, trigger_at:, input: {}, additional_metadata: {}) ⇒ Object
Create a new scheduled workflow run.
-
#delete(scheduled_id) ⇒ void
Delete a scheduled workflow run by its ID.
-
#get(scheduled_id) ⇒ Object
Retrieve a specific scheduled workflow by ID.
-
#initialize(rest_client, config) ⇒ void
constructor
Initializes a new Scheduled client instance.
-
#list(offset: nil, limit: nil, workflow_id: nil, parent_workflow_run_id: nil, statuses: nil, additional_metadata: nil, order_by_field: nil, order_by_direction: nil) ⇒ Object
List scheduled workflows based on provided filters.
-
#update(scheduled_id, trigger_at:) ⇒ Object
Reschedule a scheduled workflow run by its ID.
Constructor Details
#initialize(rest_client, config) ⇒ void
Initializes a new Scheduled client instance
28 29 30 31 32 33 |
# File 'lib/hatchet/features/scheduled.rb', line 28 def initialize(rest_client, config) @rest_client = rest_client @config = config @workflow_api = HatchetSdkRest::WorkflowApi.new(rest_client) @workflow_run_api = HatchetSdkRest::WorkflowRunApi.new(rest_client) end |
Instance Method Details
#bulk_delete(scheduled_ids: nil, workflow_id: nil, parent_workflow_run_id: nil, parent_step_run_id: nil, statuses: nil, additional_metadata: nil) ⇒ Object
Bulk delete scheduled workflow runs
Provide either scheduled_ids (explicit list) or one or more filter fields.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/hatchet/features/scheduled.rb', line 110 def bulk_delete(scheduled_ids: nil, workflow_id: nil, parent_workflow_run_id: nil, parent_step_run_id: nil, statuses: nil, additional_metadata: nil) warn "The 'statuses' filter is not supported for bulk delete and will be ignored." if statuses has_filter = [workflow_id, parent_workflow_run_id, parent_step_run_id, ].any? { |v| !v.nil? } raise ArgumentError, "bulk_delete requires either scheduled_ids or at least one filter field." unless scheduled_ids || has_filter filter_obj = nil if has_filter filter_obj = HatchetSdkRest::ScheduledWorkflowsBulkDeleteFilter.new( workflow_id: workflow_id, parent_workflow_run_id: parent_workflow_run_id, parent_step_run_id: parent_step_run_id, additional_metadata: (), ) end request = HatchetSdkRest::ScheduledWorkflowsBulkDeleteRequest.new( scheduled_workflow_run_ids: scheduled_ids, filter: filter_obj, ) @workflow_api.workflow_scheduled_bulk_delete(@config.tenant_id, request) end |
#bulk_update(updates) ⇒ Object
Bulk reschedule scheduled workflow runs
146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/hatchet/features/scheduled.rb', line 146 def bulk_update(updates) update_items = updates.map do |u| HatchetSdkRest::ScheduledWorkflowsBulkUpdateItem.new( id: u[:id], trigger_at: u[:trigger_at].utc.iso8601, ) end request = HatchetSdkRest::ScheduledWorkflowsBulkUpdateRequest.new( updates: update_items, ) @workflow_api.workflow_scheduled_bulk_update(@config.tenant_id, request) end |
#create(workflow_name:, trigger_at:, input: {}, additional_metadata: {}) ⇒ Object
Create a new scheduled workflow run
IMPORTANT: It’s preferable to use Workflow.run to trigger workflows if possible. This method is intended to be an escape hatch.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hatchet/features/scheduled.rb', line 53 def create(workflow_name:, trigger_at:, input: {}, additional_metadata: {}) request = HatchetSdkRest::ScheduleWorkflowRunRequest.new( trigger_at: trigger_at.utc.iso8601, input: input, additional_metadata: , ) @workflow_run_api.scheduled_workflow_run_create( @config.tenant_id, @config.apply_namespace(workflow_name), request, ) end |
#delete(scheduled_id) ⇒ void
This method returns an undefined value.
Delete a scheduled workflow run by its ID
74 75 76 |
# File 'lib/hatchet/features/scheduled.rb', line 74 def delete(scheduled_id) @workflow_api.workflow_scheduled_delete(@config.tenant_id, scheduled_id) end |
#get(scheduled_id) ⇒ Object
Retrieve a specific scheduled workflow by ID
199 200 201 |
# File 'lib/hatchet/features/scheduled.rb', line 199 def get(scheduled_id) @workflow_api.workflow_scheduled_get(@config.tenant_id, scheduled_id) end |
#list(offset: nil, limit: nil, workflow_id: nil, parent_workflow_run_id: nil, statuses: nil, additional_metadata: nil, order_by_field: nil, order_by_direction: nil) ⇒ Object
List scheduled workflows based on provided filters
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/hatchet/features/scheduled.rb', line 175 def list(offset: nil, limit: nil, workflow_id: nil, parent_workflow_run_id: nil, statuses: nil, additional_metadata: nil, order_by_field: nil, order_by_direction: nil) @workflow_api.workflow_scheduled_list( @config.tenant_id, { offset: offset, limit: limit, order_by_field: order_by_field, order_by_direction: order_by_direction, workflow_id: workflow_id, additional_metadata: (), parent_workflow_run_id: parent_workflow_run_id, statuses: statuses, }, ) end |
#update(scheduled_id, trigger_at:) ⇒ Object
Reschedule a scheduled workflow run by its ID
Note: the server may reject rescheduling if the scheduled run has already triggered, or if it was created via code definition (not via API).
89 90 91 92 93 94 95 |
# File 'lib/hatchet/features/scheduled.rb', line 89 def update(scheduled_id, trigger_at:) request = HatchetSdkRest::UpdateScheduledWorkflowRunRequest.new( trigger_at: trigger_at.utc.iso8601, ) @workflow_api.workflow_scheduled_update(@config.tenant_id, scheduled_id, request) end |