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
12 changes: 12 additions & 0 deletions lib/temporal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def reset_workflow(namespace, workflow_id, run_id, workflow_task_id: nil, reason
response.run_id
end

def terminate_workflow(workflow_id, namespace: nil, run_id: nil, reason: nil, details: nil)
namespace ||= Temporal.configuration.namespace

client.terminate_workflow_execution(
namespace: namespace,
workflow_id: workflow_id,
run_id: run_id,
reason: reason,
details: details
)
end

def fetch_workflow_execution_info(namespace, workflow_id, run_id)
response = client.describe_workflow_execution(
namespace: namespace,
Expand Down
22 changes: 19 additions & 3 deletions lib/temporal/client/grpc_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,32 @@ def reset_workflow_execution(namespace:, workflow_id:, run_id:, reason:, workflo
workflow_execution: Temporal::Api::Common::V1::WorkflowExecution.new(
workflow_id: workflow_id,
run_id: run_id,
request_id: SecureRandom.uuid
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a field on WorkflowExecution but on the higher ResetWorkflowExecutionRequest so I don't think this method would ever have worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it's optional, so providing a random string that we don't return anyway doesn't feel useful.

),
reason: reason,
workflow_task_finish_event_id: workflow_task_event_id
)
client.reset_workflow_execution(request)
end

def terminate_workflow_execution
raise NotImplementedError
def terminate_workflow_execution(
namespace:,
workflow_id:,
run_id:,
reason: nil,
details: nil
)
request = Temporal::Api::WorkflowService::V1::TerminateWorkflowExecutionRequest.new(
identity: identity,
namespace: namespace,
workflow_execution: Temporal::Api::Common::V1::WorkflowExecution.new(
workflow_id: workflow_id,
run_id: run_id,
),
reason: reason,
details: Serializer::Payload.new(details).to_proto
)

client.terminate_workflow_execution(request)
end

def list_open_workflow_executions
Expand Down
24 changes: 23 additions & 1 deletion spec/unit/lib/temporal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,28 @@ class TestStartWorkflow < Temporal::Workflow
end
end

describe '.terminate_workflow' do
let(:temporal_response) do
Temporal::Api::WorkflowService::V1::TerminateWorkflowExecutionResponse.new
end

before { allow(client).to receive(:terminate_workflow_execution).and_return(temporal_response) }

it 'terminates a workflow' do
described_class.terminate_workflow('my-workflow', reason: 'just stop it')

expect(client)
.to have_received(:terminate_workflow_execution)
.with(
namespace: 'default-namespace',
workflow_id: 'my-workflow',
reason: 'just stop it',
details: nil,
run_id: nil
)
end
end

describe '.schedule_workflow' do
let(:temporal_response) do
Temporal::Api::WorkflowService::V1::StartWorkflowExecutionResponse.new(run_id: 'xxx')
Expand Down Expand Up @@ -239,7 +261,7 @@ class TestStartWorkflow < Temporal::Workflow

before { allow(client).to receive(:reset_workflow_execution).and_return(temporal_response) }

context 'when decision_task_id is provided' do
context 'when workflow_task_id is provided' do
let(:workflow_task_id) { 42 }

it 'calls client reset_workflow_execution' do
Expand Down