Commit ef59a8b1 authored by Shinya Maeda's avatar Shinya Maeda Committed by Alessio Caiazza
Browse files

Introduce ProceedBuildService

parent cb10d00d47c2
......@@ -180,7 +180,7 @@ def retry(build, current_user)
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 @@ def schedulable?
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 @@ def tooltip_message
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 @@ def process_stage(index)
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 @@ def update_retried
.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