Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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: 3 additions & 3 deletions lib/temporal/activity/task_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def process

attr_reader :task, :namespace, :task_token, :activity_name, :activity_class,
:middleware_chain, :metadata, :config

def connection
@connection ||= Temporal::Connection.generate(config.for_connection)
end
Expand All @@ -71,7 +71,7 @@ def respond_completed(result)
Temporal.logger.debug("Failed to report activity task completion, retrying", metadata.to_h)
end
Temporal::Connection::Retryer.with_retries(on_retry: log_retry) do
connection.respond_activity_task_completed(task_token: task_token, result: result)
connection.respond_activity_task_completed(namespace: namespace, task_token: task_token, result: result)
end
rescue StandardError => error
Temporal.logger.error("Unable to complete Activity", metadata.to_h.merge(error: error.inspect))
Expand All @@ -85,7 +85,7 @@ def respond_failed(error)
Temporal.logger.debug("Failed to report activity task failure, retrying", metadata.to_h)
end
Temporal::Connection::Retryer.with_retries(on_retry: log_retry) do
connection.respond_activity_task_failed(task_token: task_token, exception: error)
connection.respond_activity_task_failed(namespace: namespace, task_token: task_token, exception: error)
end
rescue StandardError => error
Temporal.logger.error("Unable to fail Activity task", metadata.to_h.merge(error: error.inspect))
Expand Down
18 changes: 12 additions & 6 deletions lib/temporal/connection/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,19 @@ def poll_workflow_task_queue(namespace:, task_queue:)
poll_request.execute
end

def respond_workflow_task_completed(task_token:, commands:)
def respond_workflow_task_completed(namespace:, task_token:, commands:)
request = Temporal::Api::WorkflowService::V1::RespondWorkflowTaskCompletedRequest.new(
namespace: namespace,
identity: identity,
task_token: task_token,
commands: Array(commands).map { |(_, command)| Serializer.serialize(command) }
)
client.respond_workflow_task_completed(request)
end

def respond_workflow_task_failed(task_token:, cause:, exception: nil)
def respond_workflow_task_failed(namespace:, task_token:, cause:, exception: nil)
request = Temporal::Api::WorkflowService::V1::RespondWorkflowTaskFailedRequest.new(
namespace: namespace,
identity: identity,
task_token: task_token,
cause: cause,
Expand All @@ -210,8 +212,9 @@ def poll_activity_task_queue(namespace:, task_queue:)
poll_request.execute
end

def record_activity_task_heartbeat(task_token:, details: nil)
def record_activity_task_heartbeat(namespace:, task_token:, details: nil)
request = Temporal::Api::WorkflowService::V1::RecordActivityTaskHeartbeatRequest.new(
namespace: namespace,
task_token: task_token,
details: to_details_payloads(details),
identity: identity
Expand All @@ -223,8 +226,9 @@ def record_activity_task_heartbeat_by_id
raise NotImplementedError
end

def respond_activity_task_completed(task_token:, result:)
def respond_activity_task_completed(namespace:, task_token:, result:)
request = Temporal::Api::WorkflowService::V1::RespondActivityTaskCompletedRequest.new(
namespace: namespace,
identity: identity,
task_token: task_token,
result: to_result_payloads(result),
Expand All @@ -244,8 +248,9 @@ def respond_activity_task_completed_by_id(namespace:, activity_id:, workflow_id:
client.respond_activity_task_completed_by_id(request)
end

def respond_activity_task_failed(task_token:, exception:)
def respond_activity_task_failed(namespace:, task_token:, exception:)
request = Temporal::Api::WorkflowService::V1::RespondActivityTaskFailedRequest.new(
namespace: namespace,
identity: identity,
task_token: task_token,
failure: Serializer::Failure.new(exception).to_proto
Expand All @@ -265,8 +270,9 @@ def respond_activity_task_failed_by_id(namespace:, activity_id:, workflow_id:, r
client.respond_activity_task_failed_by_id(request)
end

def respond_activity_task_canceled(task_token:, details: nil)
def respond_activity_task_canceled(namespace:, task_token:, details: nil)
request = Temporal::Api::WorkflowService::V1::RespondActivityTaskCanceledRequest.new(
namespace: namespace,
task_token: task_token,
details: to_details_payloads(details),
identity: identity
Expand Down
3 changes: 2 additions & 1 deletion lib/temporal/workflow/task_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def fetch_full_history
def complete_task(commands)
Temporal.logger.info("Workflow task completed", metadata.to_h)

connection.respond_workflow_task_completed(task_token: task_token, commands: commands)
connection.respond_workflow_task_completed(namespace: namespace, task_token: task_token, commands: commands)
end

def fail_task(error)
Expand All @@ -103,6 +103,7 @@ def fail_task(error)
return if task.attempt > MAX_FAILED_ATTEMPTS

connection.respond_workflow_task_failed(
namespace: namespace,
task_token: task_token,
cause: Temporal::Api::Enums::V1::WorkflowTaskFailedCause::WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE,
exception: error
Expand Down
11 changes: 9 additions & 2 deletions spec/unit/lib/temporal/activity/task_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
expect(connection)
.to have_received(:respond_activity_task_failed)
.with(
namespace: namespace,
task_token: task.task_token,
exception: an_instance_of(Temporal::ActivityNotRegistered)
)
Expand Down Expand Up @@ -110,7 +111,7 @@

expect(connection)
.to have_received(:respond_activity_task_completed)
.with(task_token: task.task_token, result: 'result')
.with(namespace: namespace, task_token: task.task_token, result: 'result')
end

it 'ignores connection exception' do
Expand Down Expand Up @@ -171,6 +172,7 @@
expect(connection)
.to have_received(:respond_activity_task_failed)
.with(
namespace: namespace,
task_token: task.task_token,
exception: exception
)
Expand Down Expand Up @@ -224,6 +226,7 @@
expect(connection)
.to have_received(:respond_activity_task_failed)
.with(
namespace: namespace,
task_token: task.task_token,
exception: exception
)
Expand All @@ -248,7 +251,11 @@

expect(connection)
.to have_received(:respond_activity_task_failed)
.with(task_token: task.task_token, exception: exception)
.with(
namespace: namespace,
task_token: task.task_token,
exception: exception
)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/unit/lib/temporal/workflow/task_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

expect(connection)
.to have_received(:respond_workflow_task_completed)
.with(task_token: task.task_token, commands: commands)
.with(namespace: namespace, task_token: task.task_token, commands: commands)
end

it 'ignores connection exception' do
Expand Down Expand Up @@ -128,6 +128,7 @@
expect(connection)
.to have_received(:respond_workflow_task_failed)
.with(
namespace: namespace,
task_token: task.task_token,
cause: Temporal::Api::Enums::V1::WorkflowTaskFailedCause::WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE,
exception: exception
Expand Down Expand Up @@ -216,6 +217,7 @@
expect(connection)
.to have_received(:respond_workflow_task_failed)
.with(
namespace: namespace,
task_token: task.task_token,
cause: Temporal::Api::Enums::V1::WorkflowTaskFailedCause::WORKFLOW_TASK_FAILED_CAUSE_WORKFLOW_WORKER_UNHANDLED_FAILURE,
exception: an_instance_of(Temporal::UnexpectedResponse)
Expand Down