- token_uuid = current_api_client_authorization.andand.uuid
- container = Container.where('auth_uuid=?', token_uuid).order('created_at desc').first
- self.requesting_container_uuid = container.uuid if container
- true
+ def update_priority
+ return unless state_changed? || priority_changed? || container_uuid_changed?
+ act_as_system_user do
+ ActiveRecord::Base.connection.execute('LOCK container_requests, containers IN EXCLUSIVE MODE')
+ Container.
+ where('uuid in (?)', [self.container_uuid_was, self.container_uuid].compact).
+ map(&:update_priority!)
+ end
+ end
+
+ def set_priority_zero
+ self.update_attributes!(priority: 0) if self.state != Final
+ end
+
+ def set_requesting_container_uuid
+ return if !current_api_client_authorization
+ ActiveRecord::Base.connection.execute('LOCK container_requests, containers IN EXCLUSIVE MODE')
+ if (c = Container.where('auth_uuid=?', current_api_client_authorization.uuid).select([:uuid, :priority]).first)
+ self.requesting_container_uuid = c.uuid
+ self.priority = c.priority>0 ? 1 : 0
+ end