gitlab-org--gitlab-foss/app/services/ci/process_build_service.rb

48 lines
961 B
Ruby
Raw Normal View History

2018-09-25 01:21:41 -04:00
# frozen_string_literal: true
module Ci
2018-09-25 01:24:08 -04:00
class ProcessBuildService < BaseService
2018-09-27 03:10:55 -04:00
def execute(build, current_status)
if valid_statuses_for_build(build).include?(current_status)
2018-09-27 03:10:55 -04:00
if build.schedulable?
2018-09-28 02:55:13 -04:00
build.schedule
2018-09-27 03:10:55 -04:00
elsif build.action?
build.actionize
else
2018-10-02 05:35:34 -04:00
enqueue(build)
2018-09-27 03:10:55 -04:00
end
2018-09-28 01:41:39 -04:00
2018-09-27 03:10:55 -04:00
true
2018-09-25 01:21:41 -04:00
else
2018-09-27 03:10:55 -04:00
build.skip
false
end
end
private
2018-10-02 05:35:34 -04:00
def enqueue(build)
build.enqueue
end
def valid_statuses_for_build(build)
case build.when
2018-09-27 03:10:55 -04:00
when 'on_success'
build.scheduling_type_dag? ? %w[success] : %w[success skipped]
2018-09-27 03:10:55 -04:00
when 'on_failure'
%w[failed]
when 'always'
%w[success failed skipped]
when 'manual'
%w[success skipped]
when 'delayed'
%w[success skipped]
else
[]
2018-09-25 01:21:41 -04:00
end
end
end
end
Ci::ProcessBuildService.prepend_if_ee('EE::Ci::ProcessBuildService')