Commit 2f03c503 authored by Shinya Maeda's avatar Shinya Maeda Committed by Alessio Caiazza

Introduce ProceedBuildService

parent 422970c9
......@@ -180,7 +180,7 @@ module Ci
end
before_transition created: :scheduled do |build|
build.scheduled_at = build.get_scheduled_at
build.scheduled_at = build.options_scheduled_at
end
after_transition created: :scheduled do |build|
......@@ -263,7 +263,7 @@ module Ci
self.when == 'delayed' && options[:start_in].present?
end
def get_scheduled_at
def options_scheduled_at
ChronicDuration.parse(options[:start_in])&.seconds&.from_now
end
......
......@@ -36,7 +36,7 @@ module Ci
end
def execute_in
[0, scheduled_at - Time.now].max
scheduled? && scheduled_at && [0, scheduled_at - Time.now].max
end
private
......
# frozen_string_literal: true
module Ci
class EnqueueBuildService < BaseService
class ProceedBuildService < BaseService
def execute(build)
build.enqueue
if build.schedulable?
build.schedule!
elsif build.action?
build.actionize
else
build.enqueue
end
end
end
end
......@@ -37,7 +37,7 @@ module Ci
def process_build(build, current_status)
if valid_statuses_for_when(build.when).include?(current_status)
proceed_build(build)
Ci::ProceedBuildService.new(project, @user).execute(build)
true
else
build.skip
......@@ -103,15 +103,5 @@ module Ci
.update_all(retried: true) if latest_statuses.any?
end
# rubocop: enable CodeReuse/ActiveRecord
def proceed_build(build)
if build.schedulable?
build.schedule!
elsif build.action?
build.actionize
else
Ci::EnqueueBuildService.new(project, @user).execute(build)
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