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
10 changes: 10 additions & 0 deletions lib/cadence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def reset_workflow(domain, workflow_id, run_id, decision_task_id: nil, reason: '
response.runId
end

def terminate_workflow(domain, workflow_id, run_id, reason: 'manual termination', details: nil)
client.terminate_workflow_execution(
domain: domain,
workflow_id: workflow_id,
run_id: run_id,
reason: reason,
details: details
)
end

def fetch_workflow_execution_info(domain, workflow_id, run_id)
response = client.describe_workflow_execution(
domain: domain,
Expand Down
14 changes: 12 additions & 2 deletions lib/cadence/client/thrift_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,18 @@ def reset_workflow_execution(domain:, workflow_id:, run_id:, reason:, decision_t
send_request('ResetWorkflowExecution', request)
end

def terminate_workflow_execution
raise NotImplementedError
def terminate_workflow_execution(domain:, workflow_id:, run_id:, reason:, details: nil)
request = CadenceThrift::TerminateWorkflowExecutionRequest.new(
domain: domain,
workflowExecution: CadenceThrift::WorkflowExecution.new(
workflowId: workflow_id,
runId: run_id
),
reason: reason,
details: JSON.serialize(details),
identity: identity
)
send_request('TerminateWorkflowExecution', request)
end

def list_open_workflow_executions
Expand Down
38 changes: 38 additions & 0 deletions spec/unit/lib/cadence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,44 @@ class TestStartWorkflow < Cadence::Workflow
end
end

describe '.terminate_workflow' do
before { allow(client).to receive(:terminate_workflow_execution).and_return(nil) }

it 'terminates workflow execution' do
described_class.terminate_workflow('test-domain', 'xxx', 'yyy')

expect(client)
.to have_received(:terminate_workflow_execution)
.with(
domain: 'test-domain',
workflow_id: 'xxx',
run_id: 'yyy',
reason: 'manual termination',
details: nil
)
end

it 'terminates workflow execution with extra details' do
described_class.terminate_workflow(
'test-domain',
'xxx',
'yyy',
reason: 'test reason',
details: '{ "foo": "bar" }'
)

expect(client)
.to have_received(:terminate_workflow_execution)
.with(
domain: 'test-domain',
workflow_id: 'xxx',
run_id: 'yyy',
reason: 'test reason',
details: '{ "foo": "bar" }'
)
end
end

describe '.fetch_workflow_execution_info' do
let(:response) do
instance_double(
Expand Down