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

46 lines
846 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_when(build.when).include?(current_status)
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
2018-09-27 03:10:55 -04:00
def valid_statuses_for_when(value)
case value
when 'on_success'
%w[success skipped]
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