Skip to content

Commit d1140c3

Browse files
calum-stripeGitHub Enterprise
authored and
GitHub Enterprise
committed
Merge pull request coinbase#86 from stripe-private-oss-forks/calum-paginated-workflows
added paginated list_workflows_executions
2 parents 350720d + 8fa91a7 commit d1140c3

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

lib/temporal/client.rb

+14
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,20 @@ def list_closed_workflow_executions(namespace, from, to = Time.now, filter: {})
382382

383383
fetch_executions(:closed, { namespace: namespace, from: from, to: to }.merge(filter))
384384
end
385+
386+
# TODO: (calum, 2022-06-01) remove this once we have a better understanding of the how to do pagination on these temporal-ruby APIs
387+
def list_workflow_executions_paginated(namespace, query, next_page_token: nil)
388+
response = connection.list_workflow_executions(namespace: namespace, query: query, next_page_token: next_page_token)
389+
390+
executions = response.executions.map do |raw_execution|
391+
Temporal::Workflow::ExecutionInfo.generate_from(raw_execution)
392+
end
393+
394+
{
395+
executions: executions,
396+
next_page_token: response.next_page_token
397+
}
398+
end
385399

386400
def get_cron_schedule(namespace, workflow_id, run_id: nil)
387401
history_response = connection.get_workflow_execution_history(

lib/temporal/configuration.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
module Temporal
99
class Configuration
10-
Connection = Struct.new(:type, :host, :port, keyword_init: true)
10+
Connection = Struct.new(:type, :host, :port, :options, keyword_init: true)
1111
Execution = Struct.new(:namespace, :task_queue, :timeouts, :headers, keyword_init: true)
1212

1313
attr_reader :timeouts, :error_handlers
1414
attr_writer :converter
15-
attr_accessor :connection_type, :host, :port, :logger, :metrics_adapter, :namespace, :task_queue, :headers
15+
attr_accessor :connection_type, :host, :port, :logger, :metrics_adapter, :namespace, :task_queue, :headers, :max_page_size
1616

1717
# See https://docs.temporal.io/blog/activity-timeouts/ for general docs.
1818
# We want an infinite execution timeout for cron schedules and other perpetual workflows.
@@ -79,7 +79,10 @@ def for_connection
7979
Connection.new(
8080
type: connection_type,
8181
host: host,
82-
port: port
82+
port: port,
83+
options: {
84+
max_page_size: max_page_size
85+
},
8386
).freeze
8487
end
8588

lib/temporal/connection.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ def self.generate(configuration)
1010
connection_class = CLIENT_TYPES_MAP[configuration.type]
1111
host = configuration.host
1212
port = configuration.port
13+
options = configuration.options
1314

1415
hostname = `hostname`
1516
thread_id = Thread.current.object_id
1617
identity = "#{thread_id}@#{hostname}"
1718

18-
connection_class.new(host, port, identity)
19+
connection_class.new(host, port, identity, options)
1920
end
2021
end
2122
end

lib/temporal/connection/grpc.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,14 @@ def list_closed_workflow_executions(namespace:, from:, to:, next_page_token: nil
421421
client.list_closed_workflow_executions(request)
422422
end
423423

424-
def list_workflow_executions
425-
raise NotImplementedError
424+
def list_workflow_executions(namespace:, query:, next_page_token: nil)
425+
request = Temporal::Api::WorkflowService::V1::ListWorkflowExecutionsRequest.new(
426+
namespace: namespace,
427+
page_size: options[:max_page_size],
428+
next_page_token: next_page_token,
429+
query: query
430+
)
431+
client.list_workflow_executions(request)
426432
end
427433

428434
def list_archived_workflow_executions

0 commit comments

Comments
 (0)