miq-Utilities icon indicating copy to clipboard operation
miq-Utilities copied to clipboard

Naming lock should not request all miq_requests ever made

Open chrisruffalo opened this issue 6 years ago • 1 comments

https://github.com/RedHatOfficial/miq-Utilities/blob/1bc1939d9114aba34c2f491dcf9a25dc6b5acb24/Automate/RedHatConsulting_Utilities/Service/Provisioning/Naming.class/methods/set_vm_names.rb#L61-L64

I've been doing something similar and implemented a similar solution that uses a where clause. I think that selecting all of the previous requests (alive and dead) could lead to a situation where this method takes an unreasonably long time.

alive_requests = []
if current_request.nil?
  alive_requests = $evm.vmdb(:miq_request)
    .where(
      "type = ? and (request_state = 'active' or request_state = 'pending' or request_state = 'queued')",
      type
    )  
else 
  alive_requests = $evm.vmdb(:miq_request)
    .where(
      "id != ? and type = ? and (request_state = 'active' or request_state = 'pending' or request_state = 'queued')",
      current_request.id,
      type
    )  
end
alive_requests.each do |request|
  yield request
end

This is complicated somewhat by maintaining compatibility with a nil current_request. I think that could be implemented differently as well to make it less complicated but I'm not really familiar enough with Ruby.

chrisruffalo avatar May 22 '18 15:05 chrisruffalo

@chrisruffalo sounds like a good idea. you gonna do it?

itewk avatar Feb 26 '19 12:02 itewk