Skip to content

Commit cce6f02

Browse files
Expose count_workflow_executions on the temporal client (coinbase#272)
* Expose count_workflow_executions on the temporal client * Return a wrapped type for count_workflows response * Add integration tests * Remove debug log lines * Update lib/temporal/client.rb Fix a typo with the new return type. Co-authored-by: jazev-stripe <128553781+jazev-stripe@users.noreply.github.com> * Return the count value of count_workflow_executions instead of wrapping it * Remove the example integration spec for count_workflows. ES isn't setup in github actions and while this test is nice to have, it isn't critical to have an integration spec for it because it relies on timing due to the async visibility store --------- Co-authored-by: jazev-stripe <128553781+jazev-stripe@users.noreply.github.com>
1 parent 6a11a81 commit cce6f02

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

lib/temporal.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Temporal
3030
:list_open_workflow_executions,
3131
:list_closed_workflow_executions,
3232
:query_workflow_executions,
33+
:count_workflow_executions,
3334
:add_custom_search_attributes,
3435
:list_custom_search_attributes,
3536
:remove_custom_search_attributes,

lib/temporal/client.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,17 @@ def query_workflow_executions(namespace, query, filter: {}, next_page_token: nil
425425
Temporal::Workflow::Executions.new(connection: connection, status: :all, request_options: { namespace: namespace, query: query, next_page_token: next_page_token, max_page_size: max_page_size }.merge(filter))
426426
end
427427

428+
# Count the number of workflows matching the provided query
429+
#
430+
# @param namespace [String]
431+
# @param query [String]
432+
#
433+
# @return [Integer] an integer count of workflows matching the query
434+
def count_workflow_executions(namespace, query: nil)
435+
response = connection.count_workflow_executions(namespace: namespace, query: query)
436+
response.count
437+
end
438+
428439
# @param attributes [Hash[String, Symbol]] name to symbol for type, see INDEXED_VALUE_TYPE above
429440
# @param namespace String, required for SQL enhanced visibility, ignored for elastic search
430441
def add_custom_search_attributes(attributes, namespace: nil)

spec/unit/lib/temporal/client_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,4 +1102,28 @@ class NamespacedWorkflow < Temporal::Workflow
11021102
end
11031103
end
11041104
end
1105+
1106+
describe '#count_workflow_executions' do
1107+
let(:response) do
1108+
Temporalio::Api::WorkflowService::V1::CountWorkflowExecutionsResponse.new(
1109+
count: 5
1110+
)
1111+
end
1112+
1113+
before do
1114+
allow(connection)
1115+
.to receive(:count_workflow_executions)
1116+
.and_return(response)
1117+
end
1118+
1119+
it 'returns the count' do
1120+
resp = subject.count_workflow_executions(namespace, query: 'ExecutionStatus="Running"')
1121+
1122+
expect(connection)
1123+
.to have_received(:count_workflow_executions)
1124+
.with(namespace: namespace, query: 'ExecutionStatus="Running"')
1125+
1126+
expect(resp).to eq(5)
1127+
end
1128+
end
11051129
end

0 commit comments

Comments
 (0)