Commit 1b0b8b9c authored by Tomasz Maczukin's avatar Tomasz Maczukin

Change timeout_source to enum

parent 8ffa4809
......@@ -93,6 +93,12 @@ module Ci
chronic_duration_attr_reader :used_timeout_human_readable, :used_timeout
enum timeout_source: {
unknown_timeout_source: nil,
project_timeout_source: 1,
runner_timeout_source: 2
}
class << self
# This is needed for url_for to work,
# as the controller is JobsController
......@@ -123,10 +129,6 @@ module Ci
end
after_transition pending: :running do |build|
build.used_timeout = build.timeout
build.timeout_source = build.timeout < build.project.build_timeout ? 'runner' : 'project'
build.save!
build.run_after_commit do
BuildHooksWorker.perform_async(id)
end
......@@ -160,6 +162,11 @@ module Ci
before_transition any => [:running] do |build|
build.validates_dependencies! unless Feature.enabled?('ci_disable_validates_dependencies')
end
before_transition pending: :running do |build|
build.used_timeout = build.timeout
build.timeout_source = build.timeout < build.project.build_timeout ? :runner_timeout_source : :project_timeout_source
end
end
def detailed_status(current_user)
......
module Ci
class BuildPresenter < Gitlab::View::Presenter::Delegated
TIMEOUT_SOURCES = {
unknown_timeout_source: nil,
project_timeout_source: 'project',
runner_timeout_source: 'runner'
}.freeze
presents :build
def erased_by_user?
......@@ -18,6 +25,13 @@ module Ci
end
end
def timeout_source
return unless build.timeout_source?
TIMEOUT_SOURCES[build.timeout_source.to_sym] ||
build.timeout_source
end
def trigger_variables
return [] unless trigger_request
......
......@@ -7,7 +7,7 @@ class BuildDetailsEntity < JobEntity
expose :timeout, if: -> (*) { !build.used_timeout.nil? } do |build|
{ value: build.used_timeout_human_readable,
source: build.timeout_source }
source: build.present.timeout_source }
end
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
......
......@@ -5,6 +5,6 @@ class AddUsedTimeoutAndTimeoutSourceColumnsToCiBuilds < ActiveRecord::Migration
def change
add_column :ci_builds, :used_timeout, :integer
add_column :ci_builds, :timeout_source, :string
add_column :ci_builds, :timeout_source, :integer
end
end
......@@ -312,7 +312,7 @@ ActiveRecord::Schema.define(version: 20180327101207) do
t.boolean "protected"
t.integer "failure_reason"
t.integer "used_timeout"
t.string "timeout_source"
t.integer "timeout_source"
end
add_index "ci_builds", ["artifacts_expire_at"], name: "index_ci_builds_on_artifacts_expire_at", where: "(artifacts_file <> ''::text)", using: :btree
......
......@@ -2046,20 +2046,18 @@ describe Ci::Build do
end
shared_examples 'saves data on transition' do
it 'saves used_timeout and timeout_source on transition' do
expect(job.used_timeout).to be_nil
expect(job.timeout_source).to be_nil
job.run!
it 'saves used_timeout' do
expect { job.run! }.to change { job.reload.used_timeout }.from(nil).to(expected_timeout)
end
expect(job.used_timeout).to eq(expected_timeout)
expect(job.timeout_source).to eq(expected_timeout_source)
it 'saves timeout_source' do
expect { job.run! }.to change { job.reload.timeout_source }.from('unknown_timeout_source').to(expected_timeout_source)
end
end
context 'when runner timeout overrides project timeout' do
let(:expected_timeout) { 900 }
let(:expected_timeout_source) { 'Runner' }
let(:expected_timeout_source) { 'runner_timeout_source' }
before do
runner.maximum_job_timeout = 900
......@@ -2071,7 +2069,7 @@ describe Ci::Build do
context "when runner timeout doesn't override project timeout" do
let(:expected_timeout) { 1800 }
let(:expected_timeout_source) { 'Project' }
let(:expected_timeout_source) { 'project_timeout_source' }
before do
runner.maximum_job_timeout = 3600
......
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