Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support long poll option for get_workflow_execution_history #325

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/temporal/connection/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,18 @@ def get_workflow_execution_history(
wait_new_event: wait_for_new_event,
history_event_filter_type: HISTORY_EVENT_FILTER[event_type]
)
deadline = timeout ? Time.now + timeout : nil
client.get_workflow_execution_history(request, deadline: deadline)

loop do
deadline = timeout ? Time.now + timeout : nil
response = client.get_workflow_execution_history(request, deadline: deadline)

if wait_for_new_event && response.history.events.empty? && !response.next_page_token.empty?
request.next_page_token = response.next_page_token
next
end

return response
end
end

def poll_workflow_task_queue(namespace:, task_queue:, binary_checksum:)
Expand Down
24 changes: 24 additions & 0 deletions spec/unit/lib/temporal/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,30 @@ class NamespacedWorkflow < Temporal::Workflow
)
end.to raise_error(Temporal::TimeoutError)
end

it 'recurring polling until a close event is received'
completed_event = Fabricate(:workflow_completed_event, result: nil)
response_with_no_closed_event = Fabricate(:workflow_execution_history, events: [], _next_page_token: 'test_token')
response_with_closed_event = Fabricate(:workflow_execution_history, events: [completed_event])

expect(connection)
.to receive(:get_workflow_execution_history)
.with(
namespace: 'default-test-namespace',
workflow_id: workflow_id,
run_id: run_id,
wait_for_new_event: true,
event_type: :close,
timeout: 30,
)
.and_return(response_with_no_closed_event, response_with_closed_event)

subject.await_workflow_result(
TestStartWorkflow,
workflow_id: workflow_id,
run_id: run_id,
)
end
end

describe '#reset_workflow' do
Expand Down