debian-mirror-gitlab/app/services/ci/after_requeue_job_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.6 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Ci
class AfterRequeueJobService < ::BaseService
def execute(processable)
2022-01-26 12:08:38 +05:30
@processable = processable
process_subsequent_jobs
reset_source_bridge
2021-04-29 21:17:54 +05:30
end
private
2022-01-26 12:08:38 +05:30
def process_subsequent_jobs
dependent_jobs.each do |job|
process(job)
2021-04-29 21:17:54 +05:30
end
end
2022-01-26 12:08:38 +05:30
def reset_source_bridge
@processable.pipeline.reset_source_bridge!(current_user)
end
2022-10-11 01:57:18 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2022-01-26 12:08:38 +05:30
def dependent_jobs
2022-06-21 17:19:12 +05:30
ordered_by_dag(
2022-11-25 23:54:43 +05:30
@processable.pipeline.processables
2022-10-11 01:57:18 +05:30
.from_union(needs_dependent_jobs, stage_dependent_jobs)
.skipped
.ordered_by_stage
.preload(:needs)
2022-06-21 17:19:12 +05:30
)
2021-04-29 21:17:54 +05:30
end
2022-01-26 12:08:38 +05:30
def process(job)
Gitlab::OptimisticLocking.retry_lock(job, name: 'ci_requeue_job') do |job|
job.process(current_user)
2021-04-29 21:17:54 +05:30
end
end
2021-09-30 23:02:18 +05:30
2022-01-26 12:08:38 +05:30
def stage_dependent_jobs
2022-10-11 01:57:18 +05:30
@processable.pipeline.processables.after_stage(@processable.stage_idx)
2021-09-30 23:02:18 +05:30
end
2022-01-26 12:08:38 +05:30
def needs_dependent_jobs
2022-10-11 01:57:18 +05:30
::Gitlab::Ci::ProcessableObjectHierarchy.new(
::Ci::Processable.where(id: @processable.id)
).descendants
2021-09-30 23:02:18 +05:30
end
2022-05-07 20:08:51 +05:30
def ordered_by_dag(jobs)
sorted_job_names = sort_jobs(jobs).each_with_index.to_h
2022-10-11 01:57:18 +05:30
jobs.group_by(&:stage_idx).flat_map do |_, stage_jobs|
2022-05-07 20:08:51 +05:30
stage_jobs.sort_by { |job| sorted_job_names.fetch(job.name) }
end
end
def sort_jobs(jobs)
Gitlab::Ci::YamlProcessor::Dag.order(
jobs.to_h do |job|
[job.name, job.needs.map(&:name)]
end
)
end
# rubocop: enable CodeReuse/ActiveRecord
2021-04-29 21:17:54 +05:30
end
end