Class: Logical::Naf::ConstructionZone::Proletariat

Inherits:
Object
  • Object
show all
Defined in:
app/models/logical/naf/construction_zone/proletariat.rb

Instance Method Summary collapse

Instance Method Details

#create_historical_job(parameters, affinities, prerequisites) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/logical/naf/construction_zone/proletariat.rb', line 12

def create_historical_job(parameters, affinities, prerequisites)
  ::Naf::HistoricalJob.transaction do
    historical_job = ::Naf::HistoricalJob.create!(parameters)
    # Create affinity tabs, if affinities are provided
    affinities.each do |affinity|
      ::Naf::HistoricalJobAffinityTab.create(affinity.merge(historical_job_id: historical_job.id))
    end
    # Verify there is no loop found in prerequisites
    historical_job.verify_prerequisites(prerequisites)
    # Create historical job prerequesites, if prerequisites are provided
    prerequisites.each do |prerequisite|
      ::Naf::HistoricalJobPrerequisite.create({
                                                historical_job_id: historical_job.id,
                                                prerequisite_historical_job_id: prerequisite.id
                                              })
    end

    return historical_job
  end
end

#create_job(parameters, affinities, prerequisites) ⇒ Object



3
4
5
6
7
8
9
10
# File 'app/models/logical/naf/construction_zone/proletariat.rb', line 3

def create_job(parameters, affinities, prerequisites)
  ::Naf::HistoricalJob.transaction do
    historical_job = create_historical_job(parameters, affinities, prerequisites)
    create_queued_job(historical_job)

    return historical_job
  end
end

#create_queued_job(historical_job) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/logical/naf/construction_zone/proletariat.rb', line 33

def create_queued_job(historical_job)
  queued_job = ::Naf::QueuedJob.new(application_id: historical_job.application_id,
                                    application_schedule_id: historical_job.application_schedule_id,
                                    application_type_id: historical_job.application_type_id,
                                    command: historical_job.command,
                                    application_run_group_restriction_id: historical_job.application_run_group_restriction_id,
                                    application_run_group_name: historical_job.application_run_group_name,
                                    application_run_group_limit: historical_job.application_run_group_limit,
                                    priority: historical_job.priority)
  queued_job.id = historical_job.id
  queued_job.save!

  return queued_job
end