director/lib/director/jobs/update_release.rb
# Finds job template definitions in release manifest and sorts them into
# two buckets: new and existing job templates, then creates new job
# template records in the database and points release version to existing
# ones.
# @return [void]
Finds job template definitions in release manifest and sorts them into
two buckets: new and existing job templates, then creates new job
template records in the database and points release version to existing
ones.
Finds job template definitions in release manifest and sorts them into two buckets : new and existing job templates then creates new job template records in the database and points release version to existing ones .
def process_jobs
        logger.info("Checking for new jobs in release")
        new_jobs = []
        existing_jobs = []
        @manifest["jobs"].each do |job_meta|
          filter = {:sha1 => job_meta["sha1"]}
          if job_meta["fingerprint"]
            filter[:fingerprint] = job_meta["fingerprint"]
            filter = filter.sql_or
          end
          jobs = Models::Template.where(filter).all
          if @rebase
            substitutes = jobs.select do |job|
              job.release_id == @release_model.id &&
              job.name == job_meta["name"]
            end
            substitute = pick_best(substitutes, job_meta["version"])
            if substitute
              job_meta["version"] = substitute.version
              job_meta["sha1"] = substitute.sha1
              existing_jobs << [substitute, job_meta]
            else
              new_jobs << job_meta
            end
            next
          end
          template = jobs.find do |job|
            job.release_id == @release_model.id &&
            job.name == job_meta["name"] &&
            job.version == job_meta["version"]
          end
          if template.nil?
            new_jobs << job_meta
          else
            existing_jobs << [template, job_meta]
          end
        end
        create_jobs(new_jobs)
        use_existing_jobs(existing_jobs)
      end
def process_jobs logger . info ( "Checking for new jobs in release" ) new_jobs = [ ] existing_jobs = [ ] @manifest [ "jobs" ] . each do | job_meta | filter = { :sha1 => job_meta [ "sha1" ] } if job_meta [ "fingerprint" ] filter [ :fingerprint ] = job_meta [ "fingerprint" ] filter = filter . sql_or end jobs = Models :: Template . where ( filter ) . all if @rebase substitutes = jobs . select do | job | job . release_id == @release_model . id && job . name == job_meta [ "name" ] end substitute = pick_best ( substitutes , job_meta [ "version" ] ) if substitute job_meta [ "version" ] = substitute . version job_meta [ "sha1" ] = substitute . sha1 existing_jobs << [ substitute , job_meta ] else new_jobs << job_meta end next end template = jobs . find do | job | job . release_id == @release_model . id && job . name == job_meta [ "name" ] && job . version == job_meta [ "version" ] end if template . nil? new_jobs << job_meta else existing_jobs << [ template , job_meta ] end end create_jobs ( new_jobs ) use_existing_jobs ( existing_jobs ) end
Finds job template definitions in release manifest and sorts them into
two buckets: new and existing job templates, then creates new job
template records in the database and points release version to existing
ones.
Finds job template definitions in release manifest and sorts them into two buckets : new and existing job templates then creates new job template records in the database and points release version to existing ones .
# Checking whether we might have the same bits somewhere
None
void