Class: CPEE::DeleteInstance

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee/implementation.rb

Overview

}}}

Instance Method Summary collapse

Instance Method Details

#responseObject

{{{



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/cpee/implementation.rb', line 348

def response
  opts = @a[0]
  redis = opts[:redis]
  id = @r[0].to_i
  unless CPEE::Persistence::exists?(id,opts)
    @status = 404
    return
  end

  content = {
    :state => 'purged',
    :attributes => CPEE::Persistence::extract_list(id,opts,'attributes').to_h
  }
  state = CPEE::Persistence::extract_item(id,opts,'state')
  if state == 'stopped' || state == 'ready'
    CPEE::Message::send(:event,'state/change',File.join(opts[:url],'/'),id,content[:attributes]['uuid'],content[:attributes]['info'],content,redis)
  end

  EM::add_timer(30) do
    empt = CPEE::Persistence::keys(id,opts).to_a
    ### is there to avoid that returning calls get intro problems
    ### as we have add_timer now, it should work without this
    # empt.delete_if{|e| e =~ /\/handlers/ }
    redis.multi do |multi|
      multi.del empt
      multi.zrem 'instances', id
    end
  end
end