Class: Retab::WorkflowRuns

Inherits:
Object
  • Object
show all
Defined in:
lib/retab/workflow_runs.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ WorkflowRuns

Returns a new instance of WorkflowRuns.



9
10
11
# File 'lib/retab/workflow_runs.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#cancel(run_id:, command_id: nil, request_options: {}) ⇒ Retab::CancelWorkflowResponse

Cancel Workflow Run

Parameters:

  • run_id (String)
  • command_id (String, nil) (defaults to: nil)

    Optional idempotency key for deduplicating cancel commands

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/retab/workflow_runs.rb', line 259

def cancel(
  run_id:,
  command_id: nil,
  request_options: {}
)
  body = {
    "command_id" => command_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/v1/workflows/runs/#{Retab::Util.encode_path(run_id)}/cancel",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::CancelWorkflowResponse.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#create(workflow_id:, documents: nil, json_inputs: nil, version: nil, request_options: {}) ⇒ Retab::WorkflowRun

Create Workflow Run Route

Parameters:

  • workflow_id (String)

    Workflow id for the fresh run.

  • documents (Hash{String => Retab::MimeData, Retab::FileRef, Pathname, IO, String, Hash}, nil) (defaults to: nil)

    Mapping of start_document block IDs to their input documents.

  • json_inputs (Hash{String => Object}, nil) (defaults to: nil)

    Mapping of start-json block IDs to their input JSON data.

  • version (String, nil) (defaults to: nil)

    Workflow version to run: ‘production’, ‘draft’, or a pinned version id like ‘ver_…’. Only valid for fresh-run creation.

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/retab/workflow_runs.rb', line 118

def create(
  workflow_id:,
  documents: nil,
  json_inputs: nil,
  version: nil,
  request_options: {}
)
  documents = Retab::MimeData.coerce_document_map(documents) unless documents.nil?
  body = {
    "workflow_id" => workflow_id,
    "documents" => documents,
    "json_inputs" => json_inputs,
    "version" => version
  }.compact
  response = @client.request(
    method: :post,
    path: "/v1/workflows/runs",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::WorkflowRun.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#delete(run_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete Workflow Run

Parameters:

  • run_id (String)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)



241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/retab/workflow_runs.rb', line 241

def delete(
  run_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/v1/workflows/runs/#{Retab::Util.encode_path(run_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#export(workflow_id:, block_id:, export_source: nil, selected_run_ids: nil, selected_doc_types: nil, status: nil, exclude_status: nil, from_date: nil, to_date: nil, trigger_type: nil, preferred_columns: nil, delimiter: nil, line_delimiter: nil, quote: nil, request_options: {}) ⇒ Retab::WorkflowExportPayloadResponse

Get Workflow Export Payload

Parameters:

  • workflow_id (String)

    Workflow ID to export

  • block_id (String)

    Block ID to export

  • export_source (Retab::Types::WorkflowExportPayloadRequestExportSource, nil) (defaults to: nil)

    Use block outputs or inputs

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

    Run IDs filter (null means all runs)

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

    Doc type filter (null/empty means all)

  • status (Retab::Types::WorkflowExportPayloadRequestStatus, nil) (defaults to: nil)

    Optional status filter (intersects with completed-only export scope)

  • exclude_status (Retab::Types::WorkflowExportPayloadRequestExcludeStatus, nil) (defaults to: nil)

    Optional status exclusion filter (intersects with completed-only export scope)

  • from_date (String, nil) (defaults to: nil)

    Optional start date filter (YYYY-MM-DD)

  • to_date (String, nil) (defaults to: nil)

    Optional end date filter (YYYY-MM-DD)

  • trigger_type (Retab::Types::WorkflowExportPayloadRequestTriggerType, nil) (defaults to: nil)

    Optional trigger type filter

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

    Preferred data column order

  • delimiter (String, nil) (defaults to: nil)

    CSV field delimiter. Default is ‘;’ (the Excel EU-locale default); pass ‘,’ for RFC 4180 compatibility. Cell values are always quoted when they contain the delimiter, the line terminator, or the quote character, with embedded quotes doubled per RFC 4180.

  • line_delimiter (String, nil) (defaults to: nil)

    CSV line delimiter

  • quote (String, nil) (defaults to: nil)

    CSV quote character

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/retab/workflow_runs.rb', line 165

def export(
  workflow_id:,
  block_id:,
  export_source: nil,
  selected_run_ids: nil,
  selected_doc_types: nil,
  status: nil,
  exclude_status: nil,
  from_date: nil,
  to_date: nil,
  trigger_type: nil,
  preferred_columns: nil,
  delimiter: nil,
  line_delimiter: nil,
  quote: nil,
  request_options: {}
)
  body = {
    "workflow_id" => workflow_id,
    "block_id" => block_id,
    "export_source" => export_source,
    "selected_run_ids" => selected_run_ids,
    "selected_doc_types" => selected_doc_types,
    "status" => status,
    "exclude_status" => exclude_status,
    "from_date" => from_date,
    "to_date" => to_date,
    "trigger_type" => trigger_type,
    "preferred_columns" => preferred_columns,
    "delimiter" => delimiter,
    "line_delimiter" => line_delimiter,
    "quote" => quote
  }.compact
  response = @client.request(
    method: :post,
    path: "/v1/workflows/runs/export",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::WorkflowExportPayloadResponse.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#get(run_id:, request_options: {}) ⇒ Retab::WorkflowRun

Get Workflow Run

Parameters:

  • run_id (String)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/retab/workflow_runs.rb', line 218

def get(
  run_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/v1/workflows/runs/#{Retab::Util.encode_path(run_id)}",
    auth: true,
    request_options: request_options
  )
  result = Retab::WorkflowRun.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#list(workflow_id: nil, status: nil, exclude_status: nil, trigger_type: nil, from_date: nil, to_date: nil, min_duration_ms: nil, max_duration_ms: nil, search: nil, before: nil, after: nil, limit: 20, order: "desc", sort_by: "timing.created_at", request_options: {}) ⇒ Retab::PaginatedList<Retab::WorkflowRun>

List Workflow Runs

Parameters:

  • workflow_id (String, nil) (defaults to: nil)

    Filter by workflow ID

  • status (Retab::Types::WorkflowRunsStatus, nil) (defaults to: nil)

    Filter by run status

  • exclude_status (Retab::Types::WorkflowRunsExcludeStatus, nil) (defaults to: nil)

    Exclude runs with this status

  • trigger_type (Retab::Types::WorkflowRunsTriggerType, nil) (defaults to: nil)

    Filter by trigger type

  • from_date (String, nil) (defaults to: nil)

    Filter runs created on or after this date (YYYY-MM-DD)

  • to_date (String, nil) (defaults to: nil)

    Filter runs created on or before this date (YYYY-MM-DD)

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

    Filter runs with duration >= this value in milliseconds

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

    Filter runs with duration <= this value in milliseconds

  • search (String, nil) (defaults to: nil)

    Search by run ID (partial match)

  • before (String, nil) (defaults to: nil)
  • after (String, nil) (defaults to: nil)
  • limit (Integer, nil) (defaults to: 20)

    Items per page

  • order (Retab::Types::WorkflowRunsOrder, nil) (defaults to: "desc")
  • sort_by (String, nil) (defaults to: "timing.created_at")
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/retab/workflow_runs.rb', line 30

def list(
  workflow_id: nil,
  status: nil,
  exclude_status: nil,
  trigger_type: nil,
  from_date: nil,
  to_date: nil,
  min_duration_ms: nil,
  max_duration_ms: nil,
  search: nil,
  before: nil,
  after: nil,
  limit: 20,
  order: "desc",
  sort_by: "timing.created_at",
  request_options: {}
)
  params = {
    "workflow_id" => workflow_id,
    "status" => status,
    "exclude_status" => exclude_status,
    "trigger_type" => trigger_type,
    "from_date" => from_date,
    "to_date" => to_date,
    "min_duration_ms" => min_duration_ms,
    "max_duration_ms" => max_duration_ms,
    "search" => search,
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "sort_by" => sort_by
  }.compact
  response = @client.request(
    method: :get,
    path: "/v1/workflows/runs",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = -> (cursor) {
    list(
      workflow_id: workflow_id,
      status: status,
      exclude_status: exclude_status,
      trigger_type: trigger_type,
      from_date: from_date,
      to_date: to_date,
      min_duration_ms: min_duration_ms,
      max_duration_ms: max_duration_ms,
      search: search,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      sort_by: sort_by,
      request_options: request_options
    )
  }
  Retab::PaginatedList.from_response(
    response,
    model: Retab::WorkflowRun,
    filters: {
      workflow_id: workflow_id,
      status: status,
      exclude_status: exclude_status,
      trigger_type: trigger_type,
      from_date: from_date,
      to_date: to_date,
      min_duration_ms: min_duration_ms,
      max_duration_ms: max_duration_ms,
      search: search,
      before: before,
      limit: limit,
      order: order,
      sort_by: sort_by
    },
    fetch_next: fetch_next
  )
end