Commit fe4be8fc authored by John Cai's avatar John Cai

Add methods to save runner feature cancelable

This method adds getter/setter methods for the "cancelable" feature that
gets included in the job request payload from runner.
parent 92da3893
...@@ -23,6 +23,7 @@ module Ci ...@@ -23,6 +23,7 @@ module Ci
serialize :config_options, Serializers::SymbolizedJson # rubocop:disable Cop/ActiveRecordSerialize serialize :config_options, Serializers::SymbolizedJson # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_variables, Serializers::SymbolizedJson # rubocop:disable Cop/ActiveRecordSerialize serialize :config_variables, Serializers::SymbolizedJson # rubocop:disable Cop/ActiveRecordSerialize
serialize :runtime_runner_features, Serializers::SymbolizedJson # rubocop:disable Cop/ActiveRecordSerialize
chronic_duration_attr_reader :timeout_human_readable, :timeout chronic_duration_attr_reader :timeout_human_readable, :timeout
...@@ -49,6 +50,14 @@ module Ci ...@@ -49,6 +50,14 @@ module Ci
update(timeout: timeout.value, timeout_source: timeout.source) update(timeout: timeout.value, timeout_source: timeout.source)
end end
def set_cancel_gracefully
runtime_runner_features.merge!( { cancel_gracefully: true } )
end
def cancel_gracefully?
runtime_runner_features[:cancel_gracefully] == true
end
private private
def set_build_project def set_build_project
......
...@@ -20,6 +20,8 @@ module Ci ...@@ -20,6 +20,8 @@ module Ci
delegate :interruptible, to: :metadata, prefix: false, allow_nil: true delegate :interruptible, to: :metadata, prefix: false, allow_nil: true
delegate :has_exposed_artifacts?, to: :metadata, prefix: false, allow_nil: true delegate :has_exposed_artifacts?, to: :metadata, prefix: false, allow_nil: true
delegate :environment_auto_stop_in, to: :metadata, prefix: false, allow_nil: true delegate :environment_auto_stop_in, to: :metadata, prefix: false, allow_nil: true
delegate :set_cancel_gracefully, to: :metadata, prefix: false, allow_nil: false
delegate :cancel_gracefully?, to: :metadata, prefix: false, allow_nil: false
before_create :ensure_metadata before_create :ensure_metadata
end end
......
...@@ -121,4 +121,16 @@ RSpec.describe Ci::BuildMetadata do ...@@ -121,4 +121,16 @@ RSpec.describe Ci::BuildMetadata do
end end
end end
end end
describe 'set_cancel_gracefully' do
it 'sets cancel_gracefully' do
build.set_cancel_gracefully
expect(build.cancel_gracefully?).to be true
end
it 'returns false' do
expect(build.cancel_gracefully?).to be false
end
end
end end
...@@ -35,6 +35,8 @@ RSpec.describe Ci::Build do ...@@ -35,6 +35,8 @@ RSpec.describe Ci::Build do
it { is_expected.to respond_to(:has_trace?) } it { is_expected.to respond_to(:has_trace?) }
it { is_expected.to respond_to(:trace) } it { is_expected.to respond_to(:trace) }
it { is_expected.to respond_to(:set_cancel_gracefully) }
it { is_expected.to respond_to(:cancel_gracefully?) }
it { is_expected.to delegate_method(:merge_request?).to(:pipeline) } it { is_expected.to delegate_method(:merge_request?).to(:pipeline) }
it { is_expected.to delegate_method(:merge_request_ref?).to(:pipeline) } it { is_expected.to delegate_method(:merge_request_ref?).to(:pipeline) }
...@@ -5386,4 +5388,23 @@ RSpec.describe Ci::Build do ...@@ -5386,4 +5388,23 @@ RSpec.describe Ci::Build do
create(:ci_build) create(:ci_build)
end end
end end
describe '#runner_features' do
subject do
build.save!
build.cancel_gracefully?
end
let_it_be(:build) { create(:ci_build, pipeline: pipeline) }
it 'cannot cancel gracefully' do
expect(subject).to be false
end
it 'can cancel gracefully' do
build.set_cancel_gracefully
expect(subject).to be true
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment