-
Notifications
You must be signed in to change notification settings - Fork 107
Add ParentClosePolicy #105
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| require 'temporal/connection/serializer/base' | ||
|
|
||
| module Temporal | ||
| module Connection | ||
| module Serializer | ||
| class ParentClosePolicy < Base | ||
| def to_proto | ||
| return Temporal::Api::Enums::V1::ParentClosePolicy::PARENT_CLOSE_POLICY_UNSPECIFIED unless object | ||
| mapping = { | ||
| abandon: Temporal::Api::Enums::V1::ParentClosePolicy::PARENT_CLOSE_POLICY_ABANDON, | ||
| terminate: Temporal::Api::Enums::V1::ParentClosePolicy::PARENT_CLOSE_POLICY_TERMINATE, | ||
| request_cancel: Temporal::Api::Enums::V1::ParentClosePolicy::PARENT_CLOSE_POLICY_REQUEST_CANCEL, | ||
| }.compact | ||
|
|
||
| mapping[object.policy] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| require 'temporal/errors' | ||
|
|
||
| module Temporal | ||
| # See https://docs.temporal.io/docs/content/what-is-a-parent-close-policy/ for more information | ||
| class ParentClosePolicy | ||
| class InvalidParentClosePolicy < ClientError; end | ||
|
|
||
| attr_reader :policy | ||
|
|
||
| def initialize(policy) | ||
| @policy = policy | ||
| end | ||
|
|
||
| def validate! | ||
| unless %i[terminate abandon request_cancel].include?(@policy) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please define these as constants so they can be used without hardcoding symbols? |
||
| raise InvalidParentClosePolicy, 'Invalid parent close policy, only :abandon, :terminate, :request_cancel are allowed' | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| require 'temporal/parent_close_policy' | ||
| require 'temporal/connection/serializer/parent_close_policy' | ||
|
|
||
| describe Temporal::Connection::Serializer::ParentClosePolicy do | ||
| describe 'to_proto' do | ||
| let(:terminate_policy) { Temporal::ParentClosePolicy.new(:terminate) } | ||
| let(:abandon_policy) { Temporal::ParentClosePolicy.new(:abandon) } | ||
| let(:request_cancel_policy) { Temporal::ParentClosePolicy.new(:request_cancel) } | ||
|
|
||
| it 'converts to proto' do | ||
| expect do | ||
| described_class.new(terminate_policy).to_proto | ||
| end.not_to raise_error | ||
|
|
||
| expect do | ||
| described_class.new(abandon_policy).to_proto | ||
| end.not_to raise_error | ||
|
|
||
| expect do | ||
| described_class.new(request_cancel_policy).to_proto | ||
| end.not_to raise_error | ||
| end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please split these into 3 examples? It's easier to figure out which ones have failed that way |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| require 'temporal/parent_close_policy' | ||
|
|
||
| describe Temporal::ParentClosePolicy do | ||
| describe '#validate!' do | ||
| subject { described_class.new(param) } | ||
|
|
||
| context 'with valid param' do | ||
| %i[abandon terminate request_cancel].each do |policy| | ||
| context "with #{policy}" do | ||
| let(:param) { policy } | ||
|
|
||
| it 'does not raise' do | ||
| expect { subject.validate! }.not_to raise_error | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'with invalid param' do | ||
| let(:param) { :coinbase } | ||
|
|
||
| it 'does not raise' do | ||
| expect { subject.validate! }.to raise_error(described_class::InvalidParentClosePolicy) | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExecutionOptions are shared between workflows and activities, so this wouldn't be the best place to add workflow-specific options. Can you please move these inline with the child workflow invocation?