Class: Logical::Naf::ConstructionZone::WorkOrder

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

Direct Known Subclasses

AdHocWorkOrder, ApplicationWorkOrder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, application_type = ::Naf::ApplicationType.rails, application_run_group_restriction = ::Naf::ApplicationRunGroupRestriction.limited_per_all_machines, application_run_group_name = :command, application_run_group_limit = 1, priority = 0, affinities = [], prerequisites = [], enqueue_backlogs = false, application = nil, application_schedule = nil) ⇒ WorkOrder

Returns a new instance of WorkOrder.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 13

def initialize(command,
               application_type = ::Naf::ApplicationType.rails,
               application_run_group_restriction = ::Naf::ApplicationRunGroupRestriction.limited_per_all_machines,
               application_run_group_name = :command,
               application_run_group_limit = 1,
               priority = 0,
               affinities = [],
               prerequisites = [],
               enqueue_backlogs = false,
               application = nil,
               application_schedule = nil)
  @command = command
  @application_type = application_type
  @application_run_group_restriction = application_run_group_restriction
  @application_run_group_name = (application_run_group_name == :command ? command : application_run_group_name)
  @application_run_group_limit = application_run_group_limit
  @priority = priority
  @affinities = if affinities.nil?
                  []
                elsif affinities.is_a? Array
                  affinities
                else
                  [affinities]
                end
  @prerequisites = prerequisites
  @enqueue_backlogs = enqueue_backlogs
  @application = application
  @application_schedule = application_schedule
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def application
  @application
end

#application_run_group_limitObject (readonly)

Returns the value of attribute application_run_group_limit.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def application_run_group_limit
  @application_run_group_limit
end

#application_run_group_nameObject (readonly)

Returns the value of attribute application_run_group_name.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def application_run_group_name
  @application_run_group_name
end

#application_run_group_restrictionObject (readonly)

Returns the value of attribute application_run_group_restriction.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def application_run_group_restriction
  @application_run_group_restriction
end

#application_scheduleObject (readonly)

Returns the value of attribute application_schedule.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def application_schedule
  @application_schedule
end

#application_typeObject (readonly)

Returns the value of attribute application_type.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def application_type
  @application_type
end

#commandObject (readonly)

Returns the value of attribute command.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def command
  @command
end

#enqueue_backlogsObject (readonly)

Returns the value of attribute enqueue_backlogs.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def enqueue_backlogs
  @enqueue_backlogs
end

#priorityObject (readonly)

Returns the value of attribute priority.



3
4
5
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 3

def priority
  @priority
end

Instance Method Details

#historical_job_affinity_tab_parametersObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 56

def historical_job_affinity_tab_parameters
  @affinities.map do |affinity|
    if affinity.is_a? Symbol
      # short_name of affinity
      affinity_object = {
        affinity_id: ::Naf::Affinity.find_by_affinity_short_name(affinity).try(:id)
      }
      raise "no affinity provided" if affinity_object[:affinity_id].nil?
      affinity_object
    elsif affinity.is_a? ::Naf::Affinity
      {
        affinity_id: affinity.id
      }
    elsif affinity.is_a? ::Naf::Machine
      # affinity_for machine
      {
        affinity_id: affinity.affinity.id
      }
    elsif affinity.is_a? ::Naf::ApplicationScheduleAffinityTab
      # affinity_for application_schedule_affinity_tab
    elsif affinity.is_a? Hash
      # should have key: :affinity_id or :affinity_short_name or :affinity_name
      # may have key: :affinity_parameter
      affinity_object = {}
      if affinity.has_key?(:affinity_id)
        affinity_object[:affinity_id] = affinity[:affinity_id]
      elsif affinity.has_key?(:affinity_name)
        affinity_object[:affinity_id] = ::Naf::Affinity.find_by_affinity_name(affinity[:affinity_name]).try(:id)
      elsif affinity.has_key?(:affinity_short_name)
        affinity_object[:affinity_id] = ::Naf::Affinity.find_by_affinity_short_name(affinity[:affinity_short_name]).try(:id)
      end
      raise "no affinity provided" if affinity_object[:affinity_id].nil?
      affinity_object[:affinity_parameter] = affinity[:affinity_parameter] if affinity.has_key?(:affinity_parameter)
      affinity_object
    else
      raise "unknown affinity kind: #{affinity.inspect}"
    end
  end
end

#historical_job_parametersObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 43

def historical_job_parameters
  {
    command: command,
    application_type_id: application_type.id,
    application_run_group_restriction_id: application_run_group_restriction.id,
    application_run_group_name: application_run_group_name,
    application_run_group_limit: application_run_group_limit,
    priority: priority,
    application_id: application.try(:id),
    application_schedule_id: application_schedule.try(:id)
  }
end

#historical_job_prerequisite_historical_jobsObject



96
97
98
99
100
101
102
103
104
# File 'app/models/logical/naf/construction_zone/work_order.rb', line 96

def historical_job_prerequisite_historical_jobs
  # the idea here is that if it is a historical job its prerequisites have
  # already been checked, we only need to check if the prerequisites are NOT
  # the current job we are inserting (which can't happen in the current code path)
  @prerequisites.each do |prerequisite|
    raise "found a non Naf::HistoricalJob in prerequisites: #{prerequisite.inspect}" unless prerequisite.is_a? ::Naf::HistoricalJob
  end
  return @prerequisites
end