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

Introduce ProceedBuildService

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