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)
|
2020-02-14 16:09:08 -05:00
|
|
|
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
|
|
|
|
|
2020-02-14 16:09:08 -05:00
|
|
|
def valid_statuses_for_build(build)
|
|
|
|
case build.when
|
2018-09-27 03:10:55 -04:00
|
|
|
when 'on_success'
|
2020-02-14 16:09:08 -05:00
|
|
|
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
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
Ci::ProcessBuildService.prepend_if_ee('EE::Ci::ProcessBuildService')
|