Project

General

Profile

Download (1.04 KB) Statistics
| Branch: | Tag: | Revision:

foreman_pipeline / app / lib / actions / foreman_pipeline / job / repo_sync_job_hook.rb @ be52ca64

1
module Actions
2
  module ForemanPipeline
3
    module Job
4
      class RepoSyncJobHook < JobHook
5
        
6
        def self.subscribe
7
          Katello::Repository::Sync
8
        end
9

    
10
        def plan(repo)
11
          valid_jobs = repo.jobs.select { |job| job.is_valid? }
12

    
13
          jobs_to_run = valid_jobs.select { |job| job.target_cv_version_avail? }
14
          allowed_jobs = jobs_to_run.select { |job| job.sync_trigger && !job.version_already_promoted? }
15
          grouped_jobs = allowed_jobs.group_by(&:target_cv_version).values
16

    
17
          if grouped_jobs.max_by(&:length).length > 1
18
            grouped_jobs = grouped_jobs.max_by(&:length)
19

    
20
            plan_self(:trigger => trigger.output,
21
                      :job_ids => grouped_jobs.map(&:id),
22
                      :job_names => grouped_jobs.map(&:name))
23
          else
24
            grouped_jobs.flatten!
25
            plan_self(:trigger => trigger.output,
26
                      :job_names => [],
27
                      :job_ids => grouped_jobs.map(&:id))
28
          end
29
        end
30
      end
31
    end
32
  end
33
end