Skip to content
Draft
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
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ PROTO_OUT := lib/gen
proto:
$(foreach PROTO_DIR,$(PROTO_DIRS),bundle exec grpc_tools_ruby_protoc -Iproto --ruby_out=$(PROTO_OUT) --grpc_out=$(PROTO_OUT) $(PROTO_DIR)*.proto;)

# Need to only load imports if not disabled
sed -i "/require 'temporal/ s|\(.*\)|\1 unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'|" \
lib/gen/temporal/api/operatorservice/v1/service_services_pb.rb
sed -i "/require 'temporal/ s|\(.*\)|\1 unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'|" \
lib/gen/temporal/api/workflowservice/v1/service_services_pb.rb

.PHONY: proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/temporal.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Protoc wants all of its generated files on the LOAD_PATH
$LOAD_PATH << File.expand_path('./gen', __dir__)
# Protoc wants all of its generated files on the LOAD_PATH. Only require protos if not disabled.
unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'
$LOAD_PATH << File.expand_path('./gen', __dir__)
end

require 'securerandom'
require 'forwardable'
Expand Down
40 changes: 23 additions & 17 deletions lib/temporal/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,25 +230,31 @@ def await_workflow_result(workflow, workflow_id:, run_id: nil, timeout: nil, nam
execution_options = ExecutionOptions.new(workflow, options, config.default_execution_options)
max_timeout = Temporal::Connection::GRPC::SERVER_MAX_GET_WORKFLOW_EXECUTION_HISTORY_POLL
history_response = nil
begin
history_response = connection.get_workflow_execution_history(
namespace: execution_options.namespace,
workflow_id: workflow_id,
run_id: run_id,
wait_for_new_event: true,
event_type: :close,
timeout: timeout || max_timeout,
)
rescue GRPC::DeadlineExceeded => e
message = if timeout
"Timed out after your specified limit of timeout: #{timeout} seconds"
else
"Timed out after #{max_timeout} seconds, which is the maximum supported amount."
closed_event = nil
loop do
begin
history_response = connection.get_workflow_execution_history(
namespace: execution_options.namespace,
workflow_id: workflow_id,
run_id: run_id,
wait_for_new_event: true,
event_type: :close,
timeout: timeout || max_timeout,
)
rescue GRPC::DeadlineExceeded => e
message = if timeout
"Timed out after your specified limit of timeout: #{timeout} seconds"
else
"Timed out after #{max_timeout} seconds, which is the maximum supported amount."
end
raise TimeoutError.new(message)
end
raise TimeoutError.new(message)
history = Workflow::History.new(history_response.history.events)
closed_event = history.events.first

break if closed_event
end
history = Workflow::History.new(history_response.history.events)
closed_event = history.events.first

case closed_event.type
when 'WORKFLOW_EXECUTION_COMPLETED'
payloads = closed_event.attributes.result
Expand Down
16 changes: 11 additions & 5 deletions lib/temporal/connection/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
require 'google/protobuf/well_known_types'
require 'securerandom'
require 'json'
require 'gen/temporal/api/filter/v1/message_pb'
require 'gen/temporal/api/workflowservice/v1/service_services_pb'
require 'gen/temporal/api/operatorservice/v1/service_services_pb'
require 'gen/temporal/api/enums/v1/workflow_pb'
require 'gen/temporal/api/enums/v1/common_pb'
require 'temporal/connection/errors'
require 'temporal/connection/interceptors/client_name_version_interceptor'
require 'temporal/connection/serializer'
Expand All @@ -16,6 +11,17 @@
require 'temporal/connection/serializer/schedule'
require 'temporal/connection/serializer/workflow_id_reuse_policy'

# Only require protos if not disabled. This env var is commonly set to work alongside the temporalio/sdk-ruby project.
unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'
require 'gen/temporal/api/filter/v1/message_pb'
require 'gen/temporal/api/enums/v1/workflow_pb'
require 'gen/temporal/api/enums/v1/common_pb'
end

# These are gRPC stubs, not protos, and therefore are not disabled when protos are
require 'gen/temporal/api/workflowservice/v1/service_services_pb'
require 'gen/temporal/api/operatorservice/v1/service_services_pb'

module Temporal
module Connection
class GRPC
Expand Down
8 changes: 6 additions & 2 deletions lib/temporal/connection/serializer/base.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'oj'
require 'gen/temporal/api/common/v1/message_pb'
require 'gen/temporal/api/command/v1/message_pb'

# Only require protos if not disabled
unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'
require 'gen/temporal/api/common/v1/message_pb'
require 'gen/temporal/api/command/v1/message_pb'
end

module Temporal
module Connection
Expand Down
5 changes: 5 additions & 0 deletions lib/temporal/connection/serializer/schedule_overlap_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require "temporal/connection/serializer/base"

# Only require protos if not disabled
unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'
require "gen/temporal/api/enums/v1/schedule_pb"
end

module Temporal
module Connection
module Serializer
Expand Down
6 changes: 5 additions & 1 deletion lib/temporal/testing/replay_tester.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require "gen/temporal/api/history/v1/message_pb"
require "json"
require "temporal/errors"
require "temporal/metadata/workflow_task"
require "temporal/middleware/chain"
require "temporal/workflow/executor"
require "temporal/workflow/stack_trace_tracker"

# Only require protos if not disabled
unless ENV['COINBASE_TEMPORAL_RUBY_DISABLE_PROTO_LOAD'] == '1'
require "gen/temporal/api/history/v1/message_pb"
end

module Temporal
module Testing
class ReplayError < StandardError
Expand Down
25 changes: 25 additions & 0 deletions spec/unit/lib/temporal/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,31 @@ class NamespacedWorkflow < Temporal::Workflow
)
end

it 'retries if there is till there is no closed event' do
completed_event = Fabricate(:workflow_completed_event, result: nil)
response_with_no_closed_event = Fabricate(:workflow_execution_history, events: [])
response_with_closed_event = Fabricate(:workflow_execution_history, events: [completed_event])

expect(connection)
.to receive(:get_workflow_execution_history)
.with(
namespace: 'some-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(
NamespacedWorkflow,
workflow_id: workflow_id,
run_id: run_id,
)
end

it 'can override the namespace' do
completed_event = Fabricate(:workflow_completed_event, result: nil)
response = Fabricate(:workflow_execution_history, events: [completed_event])
Expand Down