Class: RamWorkload

Inherits:
Workload
  • Object
show all
Defined in:
app/models/ram_workload.rb

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'app/models/ram_workload.rb', line 16

def as_json(options={})
  hash = {}
  hash[:id] = self.id
  hash[:ram_mb_required] = self.ram_mb_required
  hash[:ram_mb_required_user_capacity] = self.ram_mb_required_user_capacity
  hash[:ram_mb_growth_per_user] = self.ram_mb_growth_per_user
  hash[:ingredient_id] = self.ingredient_id
  hash
end

#min_ram(num_users) ⇒ Object


12
13
14
# File 'app/models/ram_workload.rb', line 12

def min_ram(num_users)
  self.ram_mb_required + (num_users * self.ram_mb_growth_per_user).ceil
end

#to_constraint(num_users) ⇒ Object


5
6
7
8
9
10
# File 'app/models/ram_workload.rb', line 5

def to_constraint(num_users)
  self.ingredient.ram_constraint.destroy if self.ingredient.ram_constraint.present?
  self.ingredient.ram_constraint = RamConstraint.create(
    min_ram: min_ram(num_users)
  )
end