- return if ![Queued, Locked, Running].include?(state)
- p = ContainerRequest.
- where('container_uuid=? and priority>0 and state=?', uuid, ContainerRequest::Committed).
- select("priority, requesting_container_uuid, created_at").
- lock(true).
- map do |cr|
- if cr.requesting_container_uuid
- Container.where(uuid: cr.requesting_container_uuid).pluck(:priority).first
- else
- (cr.priority << 50) - (cr.created_at.to_time.to_f * 1000).to_i
- end
- end.max || 0
- update_attributes!(priority: p)
- end
-
- def propagate_priority
- return true unless saved_change_to_priority?
- act_as_system_user do
- # Update the priority of child container requests to match new
- # priority of the parent container (ignoring requests with no
- # container assigned, because their priority doesn't matter).
- ContainerRequest.
- where('requesting_container_uuid = ? and state = ? and container_uuid is not null',
- self.uuid, ContainerRequest::Committed).
- pluck(:container_uuid).each do |container_uuid|
- Container.find_by_uuid(container_uuid).update_priority!
- end
- end