diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/build.rb | 23 | ||||
-rw-r--r-- | app/workers/build_finished_worker.rb | 1 | ||||
-rw-r--r-- | app/workers/ci/build_schedule_worker.rb | 6 |
3 files changed, 20 insertions, 10 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index be4a6c553e1..6ea574ed8ec 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -186,9 +186,8 @@ module Ci end after_transition any => [:manual] do |build| - puts "#{self.class.name} - #{__callee__}: 1" build.run_after_commit do - build.schedule_delayed_execution + build.schedule end end @@ -237,22 +236,30 @@ module Ci action? && (manual? || retryable?) end - def delayed? + def schedulable? manual? && options[:start_in].present? end - def execute_at - ChronicDuration.parse(options[:start_in])&.seconds&.from_now + def scheduled? + build.build_schedule.exist? end - def schedule_delayed_execution - return unless delayed? + def schedule + return unless schedulable? create_build_schedule!(execute_at: execute_at) end + def unschedule + build&.build_schedule&.delete + end + + def execute_at + ChronicDuration.parse(options[:start_in])&.seconds&.from_now + end + def action? - self.when == 'manual' || self.when == 'delayed' + %w[manual delayed].include?(self.when) end # rubocop: disable CodeReuse/ServiceClass diff --git a/app/workers/build_finished_worker.rb b/app/workers/build_finished_worker.rb index 889384d6be8..51cbbe8882e 100644 --- a/app/workers/build_finished_worker.rb +++ b/app/workers/build_finished_worker.rb @@ -9,7 +9,6 @@ class BuildFinishedWorker # rubocop: disable CodeReuse/ActiveRecord def perform(build_id) Ci::Build.find_by(id: build_id).try do |build| - build&.build_schedule&.delete # We execute that in sync as this access the files in order to access local file, and reduce IO BuildTraceSectionsWorker.new.perform(build.id) BuildCoverageWorker.new.perform(build.id) diff --git a/app/workers/ci/build_schedule_worker.rb b/app/workers/ci/build_schedule_worker.rb index 448fb5bf41e..9f81aa3c71e 100644 --- a/app/workers/ci/build_schedule_worker.rb +++ b/app/workers/ci/build_schedule_worker.rb @@ -9,7 +9,11 @@ module Ci ::Ci::Build.preload(:build_schedule).find_by(id: build_id).try do |build| break unless build.build_schedule.present? - Ci::PlayBuildService.new(build.project, build.user).execute(build) + begin + Ci::PlayBuildService.new(build.project, build.user).execute(build) + ensure + build.unschedule + end end end end |